Lewis Hamilton was made to settle for third on the grid in Mexico as Sebastian Vettel kept his slim world championship hopes alive by storming to pole position.

Max Verstappen appeared on course to become Formula One's youngest ever pole sitter only for Vettel to beat the Red Bull driver with the final lap of a dramatic qualifying session at the Autodromo Hermanos Rodriguez.

Vettel, who trails Hamilton by 66 points with just three grands prix remaining, must finish either first or second in Sunday's race to stand any chance of taking the championship battle on to the penultimate round in Brazil.

But despite Hamilton's relatively lowly grid slot the Englishman needs to cross the line only fifth to seal his fourth crown on Sunday.

Hamilton has been in blistering form since the summer break after winning five of the six grands prix staged, including a dominant victory in Austin, Texas last weekend.

But the British driver has his work cut out to secure his fourth world championship in style after a rousing performance from Vettel.

The German delivered a dizzying time at a track which is more than 2,300 metres above sea level, to edge out Verstappen by just eight hundredths of a second and claim the 50th pole of his career.

Hamilton was nearly half a second further back in third with his Mercedes team-mate Valtteri Bottas fourth on the grid.

Hamilton however, could be bumped up to second with Verstappen under investigation from the stewards for allegedly blocking Bottas earlier in qualifying.

Verstappen was controversially stripped of his podium finish last Sunday in Austin after he was penalised for an illegal last-lap overtake on Kimi Raikkonen.

Raikkonen finished fifth in the order ahead of Force India's Esteban Ocon, with Daniel Ricciardo a disappointing seventh.

"Congrats to Sebastian on reaching 50 poles," Hamilton said. "I tried to deny him but it wasn't to be. It was a difficult session and it has been a difficult weekend.

"They did a great job and their car was working better than ours this weekend, but I am still there in the fight.

"The race pace is good so I am not worried about that, but you can't overtake here. There is a long way down to turn one so we should have some fun tomorrow."