With barely seconds to spare and hardly any fuel left in his car's tank, the Briton roared around the Circuit Gilles Villeneuve in one minute 15.105 seconds to end Red Bull's hopes of an eighth pole in a row.
Australia's Mark Webber, the championship leader who had started on pole in the three previous races, had to settle for a share of the front row with the 2008 world champion after posting the second quickest time.
Webber's German team-mate Sebastian Vettel was third quickest with Spain's Fernando Alonso fourth for Ferrari.
Hamilton's team-mate and reigning world champion Jenson Button was fifth after only just sneaking into the final stage of qualifying with a blistering last lap in the second session.
The pole was Hamilton's third in a row in Montreal, which was left off last year's Formula One calendar. The 25-year-old won his first race here in 2007.
While Red Bull had qualified fastest for every race this season, McLaren were tipped to unseat them in Canada because the street circuit's long straights and hairpin corners better suit their cars.
McLaren had dominated practice, setting the fastest times in two of three practice sessions, but Red Bull threatened to again upstage them when Webber had the quickest qualifying time of 1:15.373 with only seconds to go.
Hamilton managed to get across the finish line just before the session expired to start one last flying lap and beat Webber's time to grab his 18th career pole and first since Abu Dhabi last year.