The Mercedes driver headed team-mate Valtteri Bottas and Max Verstappen, but an engine penalty will see him start from the midfield tomorrow.
Daniel Ricciardo was a high-profile early casualty, eliminated in Qualifying 1 as McLaren seemingly got the timing wrong in changeable conditions early in the session.
With rain expected during the qualifying hour, a queue formed at pit exit two minutes before the session commenced.
All 20 drivers immediately headed out, leading to a traffic jam in the final sequence of corners.
Hamilton ran wide at Turn 1 on his first flying lap, his time deleted as he struggled for grip in cool conditions.
Carlos Sainz and Verstappen also had issues at the opening corner, both spinning as they started their laps.
George Russell was the early pace setter, his 1:28.047s putting the Williams fastest for a time.
As rain began to fall, Verstappen recorded a 1:26.692s to usurp Hamilton's 1:27.085s.
Most drivers opted to stay on track for a second flying lap, Bottas improving to a 1:25.913s as conditions began to improve.
Norris has risen to second with Verstappen third, Hamilton's earlier effort seeing him just sixth with nine minutes remaining.
Gasly then went fastest, the AlphaTauri having shown well in Free Practice 3, to record a 1:25.486s and take provisional pole.
Sitting in 10th, Hamilton headed back out for a second run to safeguard himself against elimination in uncertain conditions.
The Mercedes driver delivered a 1:25.050s to top the timesheets, Bottas second fastest less than a tenth slower than his team-mate.
Verstappen soon went faster, a 1:25.033s scarcely 0.01s quicker than Hamilton's effort – though the lap was soon after deleted for track limits at Turn 1.
Inside the final minute of Qualifying 1, Ricciardo improved from 13th to eighth on a 1:25.881s.
However, it wasn't enough and he found himself eliminated along with Nikita Mazepin, Kimi Raikkonen, Antonio Giovinazzi, and Nicholas Latifi.
The McLaren driver's fate was sealed when Carlos Sainz improved with his final lap, a seemingly canny strategic play by Ferrari in their private battle for third in the constructors' championship.
Ricciardo's consternation was Mick Schumacher's elation, the German 14th fastest, 0.3s clear of the drop zone and only 0.1s away from the top 10.
His time was also nearly three seconds faster than team-mate Nikita Mazepin, who had a number of spins during the segment.
Mercedes headed the field onto the track as Qualifying 2 began, medium tyres fitted to both cars.
Bottas was the fastest out of the gates, a 1:24.142s as Hamilton opted for two warmup laps.
Verstappen recorded a 1:24.002s with his first lap in the segment before Hamilton unleashed a 1:23.595s, 0.4s clear of the pack.
A spin from Charles Leclerc cost the Ferrari driver a chance to improve, the Monegasque sitting 10th at the time.
The final Qualifying 2 runs saw Verstappen unable to improve, while Sergio Perez was able to bank the third fastest time, a 1:23.961 to slot in behind the Mercedes duo.
Though already fastest, Hamilton improved to 1:23.082s as Lance Stroll ran off the road at Turn 1.
Eighth fastest, and without the time to complete the lap for another go, he was left vulnerable.
Sainz headed out for a single lap, offering a slipstream to team-mate Leclerc for his final effort lap without setting a time of his own.
He was therefore eliminated, along with Schumacher, Russell, who ran wide at the final corner, Esteban Ocon, and Vettel.
All surviving runners headed out as Qualifying 3 began, the threat of rain having long since passed.
Hamilton was the first out, recording a 1:23.093s which lasted only seconds before Bottas logged a 1:23.071s.
Gasly was third fastest on his first flying lap, quicker than Perez before Verstappen slotted in third with a 1:23.298s.
With five minutes to run, Hamilton headed out early for his final run – the only man on circuit at the time.
Half a lap later, Leclerc headed out, followed by Yuki Tsunoda, Hamilton catching the pair as he headed down the back straight.
The resulting time was a 1:22.868s to move the needle nearly 0.3s clear of Bottas in second.
Verstappen started his final lap with a minute remaining setting a personal best first sector.
He was equally quick through the second split, though a slow final third of the lap left him resigned to third.
Bottas improved to 1:22.998s with his final lap to inch closer to Hamilton but remained second fastest.
Leclerc rose to fourth as he pushed Gasly down to fifth, followed by Alonso, Perez, Norris, Stroll, and Tsunoda.
The result means Bottas will start from pole for Sunday's race courtesy of Hamilton's grid penalty, which will leave the championship leader 11th.
It also makes for five different cars in the top five spots on the grid, and four Red Bull backed machines in the top 10.
The Turkish Grand Prix gets underway at 23:00 AEDT on Sunday.
Results: Formula 1 Turkish Grand Prix, Qualifying
|Red Bull Racing
|Red Bull Racing