The three-time champion Briton resisted a powerful late challenge in the final seconds of Q3 from championship-leading four-time champion Sebastian Vettel of Ferrari.
"It was very close, but well done to Lewis," said Vettel. "And a big thank-you to my team. I'm afraid it was my lock-up at the end of the lap that made the difference.
"It was a really good lap up to the final chicane."
A beaming Hamilton, who has bounced back to his best form after a puzzling loss of pace in Russia, said his first lap had been "very, very good, but the last lap was only so-so... But I am super proud that we are back up there."
More From This Section
It was the 64th pole of Hamilton's career, lifting him to within one of his childhood hero Brazilian Ayrton Senna, on 65, and four from German Michael Schumacher on 68.
Finns Valtteri Bottas, in the second Mercedes, who also had an engine change on Saturday morning, and Kimi Raikkonen, in the second Ferrari, were third and fourth fastest.
Dutch teenager Max Verstappen, who won last year's race on debut with Red Bull, was fifth ahead of his team-mate Australian Daniel Ricciardo with local hero Fernando Alonso grabbing a very popular seventh against the odds for McLaren- Honda.
In his third new power unit of the four permitted this year, Vettel used team radio to thank his mechanics for their efforts before being told "stop the car" on his installation lap.
"Are you sure?" he responded, wisely. After making a 'driver default' change in the car, Vettel was soon back up to speed. "Seems better now," he said, as he clocked an early fastest lap in 1:20.939.
As Q2 began, Mercedes reminded Hamilton "this is our race start set" of tyres, a message not heeded by Bottas who locked up at Turn One and flat-spotted his tyres, requiring a second hot lap.
Hamilton ran wide at Turn Five, but was fastest in Q2 by a narrow margin -- less than a tenth -- ahead of Vettel and Bottas, but the lap that lifted the crowd came from Alonso, who reached the top ten shootout for the first time this year, 24 hours after yet another engine failure on Friday.