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."
Hamilton clocked a best lap of one minute and 19.149 seconds to stay ahead of Vettel, who clocked 1:19.200, by the narrowest of margins after the German had required a rapid engine change shortly before the session began.
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.
On a perfect, if windy, spring day, the session began with a track temperature of 44 degrees Celsius and Vettel hurrying to join the fray after Ferrari had changed his engine following a water leak problem discovered in final practice.
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.
Hamilton trimmed four-tenths off that to set the Q1 pace, with Bottas third ahead of Raikkonen, who soon improved to second.
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.
For the Spaniard, who is heading to the Indianapolis 500 instead of Monaco later this month, it was a personal triumph four years after his last victory, with Ferrari in Spain, in 2013.
(This story has not been edited by Business Standard staff and is auto-generated from a syndicated feed.)