Max Verstappen won the intra-team battle at Red Bull, finishing ahead of Daniel Ricciardo by just 0.003s.
The reigning world champ hopes to do better than his last time in the pole position, when he finished second behind Ferrari’s German driver Sebastian Vettel.
Meanwhile, it took four races for teammate Hamilton to finally triumph – the longest start-of-season drought for a Mercedes driver since the introduction of turbo hybrid engines in 2014.
“It will be interesting to see how much performance the teams can find with their upgrades”, said Mercedes team boss Toto Wolff.
“And I am sure there have been people with nerves over the last few races, just not really understanding [what’s happening] and feeling like we’re not really learning enough”.
There were big cheers from the crowd for Hartley, in his first full season in F1, as he climbed from the wreckage of his vehicle.
After making his pole position stick into turn one and waiting patiently during a six-lap period under the safety vehicle, Hamilton rapidly stretched his lead over championship rival Sebastian Vettel, who had overtaken Valtteri Bottas at the start.
Carlos Sainz was eighth fastest for Renault, 0.064s quicker than compatriot Fernando Alonso in the updated McLaren.
Charles Leclerc of Sauber and Sergio Perez of Force India closed out the top 10. Over more than a quarter-century, nearly 90 per cent of races here have been won from the front row, the highest ratio among venues that have held at least 10 events.
Vettel gave away his position when Ferrari made a decision to go for an extra stop and give the German driver fresher tires.
“Everything we bring to the track is delivering the expectations and the lap times we were expecting from them”, Alonso said.
Starting from pole position for only the second time this season, Hamilton eased away at the front once racing resumed after a first-lap incident triggered by Romain Grosjean. Vettel won in Australia and Bahrain, while Ricciardo was first in China and Hamilton triumphed in Azerbaijan.
As he spun back across the track, Nico Hulkenberg tried to take avoiding action in his Renault but had his rear wheel caught by Grosjean’s vehicle, and Toro Rosso’s Pierre Gasly, unsighted, smashed into the side of the Haas.
‘Then the sport said the cars are too slow, so let’s put more aerodynamic bits on the cars and make them wider and more spectacular.
Clearly upset and crestfallen, Grosjean kept his helmet on as he slumped on some nearby steps before going to the medical centre for a check-up.
‘We always want to go faster, improve the technology, push the boundaries and the limits, ‘ Hamilton said in the minutes after claiming the 74th pole of his career, and his third in as many races in Spain.
“We’ve got a lot of work to do for tomorrow, it’ll be a tough race, but it’s a good way to start the weekend”.