Vettel emerged from his penalty just ahead of Hamilton, and the German fought his way back up to fourth to finish one place in front of his rival in the race of the season and stretch his lead to 14 points.
Just as in Canada a fortnight previously, Hamilton made it count when it mattered the most to finish almost half-a-second clear of his Mercedes team-mate Valtteri Bottas in qualifying, with Vettel a distant fourth.
"I thought the hunger might drop off after I matched him (Senna)", Hamilton said.
The entirety of the field made use of the safety auto to pit and switch to the soft tire that would likely take them to the end of the race, with Hamilton heading the field ahead of Vettel and Perez for the restart on Lap 17.
Hamilton made a mistake on his first lap in final qualifying and was anxious he would not be able to make amends when a crash halted the session. Bottas was on provisional pole when the session was red flagged with three and half minutes left to go. Valtteri Bottas from the same team came in second (1:41.027), and Kimi Raikkonen from Ferrari F1 team came in third (1:41.693).
Lewis Hamilton from Mercedes took pole with a time of 1:40.593. But just when it seemed that he was going to carry on in that vein in Q3, he made a mistake in the final corner on his first run, and suddenly it was Bottas on the pole, with 1m 41.274s to 1m 41.428s.
The top three was now Lewis Hamilton, Sebastian Vettel and Sergio Perez, and remained that way until Lap 12 when Max Verstappen started to challenge Perez for the last podium spot. But they made some fantastic changes that put us in the right direction, and we made more after the third practice session.
The slowness of the safety auto was annoying Hamilton, who complained that he couldn't get enough temperature into his tires. "I'm so pumped, that's how qualifying should be".
"It was a great lap", Hamilton said. "Obviously I was going for the pole and just the lap in the end wasn't ideal". I came across the line so happy because even if I was second it was still an awesome one, single lap, which I was really proud of. Vettel, having served a 10-second stop-and-go, rejoined right ahead of Hamilton, who had had a loose headrest fixed. "Nobody else, I think, can do that". "On the cool-down lap, I was just giggling like a schoolboy".
Alonso will start in an embarrassing 16th and Vandoorne next to last in 19th.
The first safety vehicle came in after 16 laps, racing resuming with Perez making an attack on Vettel who resisted, before another safety auto, the second, was deployed due to debris.
"It's going to be a long race and looking at all the practices, there's going to be a lot going on".