Lewis Hamilton claimed his second successive pole position of the new season in China on Saturday. He was, however, pushed to the limit again by Ferrari’s Sebastian Vettel, who finished second, one-thousandth of a second in front of Hamilton’s team-mate, Valtteri Bottas.

Hamilton saved the best to last, setting a flawless pole lap on his final run in Q3. But Ferrari have proved once again they have the pace this season to match Mercedes and with rain forecast for Sunday in Shanghai, the race could be a feisty spectacle.

“We knew it was going to be close,” said Hamilton. “It was going to mean we would have to pull out all the stops and really have a very, very perfect lap. I managed to just chip away at it from session to session. No major issues. But the last lap was my best lap, which is always the plan.

“It is more exciting than ever for me because we are really fighting with these guys. It is amazing and that is what racing is all about, and it really pushes you to raise the bar every time you go out, which I love.”

The second Ferrari, driven by Kimi Raikkonen, will start from fourth but the best Red Bull could manage was fifth, with Daniel Ricciardo more than a second back from the pole-sitter’s pace. Max Verstappen, suffering from a power problem in his Red Bull, was knocked out of Q1 and will be 17th on the grid.

Vettel, however, who started from second at Melbourne and went on to win, was optimistic for Sunday. “We can still improve. Let’s see what the race looks like. The conditions will be quite different,” he said. “The car is good, so I’m confident, no matter the conditions that the car is working.”

Hamilton has not driven on the full wet tyre this season, having not done so in testing due to an electrical fault on his car. Should the rain come – and the forecast is that it is very likely – it will bring a fresh challenge. “Ferrari have a very, very strong car, a step up more so in the race pace and how they treat their tyres, particularly when it’s warm, so it will be interesting to see what the weather brings,” he said. “Whatever the case it’s going to be close between us and that bodes well for one of the most exciting days to come for a long time.”

This was the 63rd pole position of Hamilton’s career, putting him two behind Ayrton Senna and five behind Michael Schumacher in the single lap discipline. Hamilton’s time of 1min 31.678sec was two-tenths in front of Vettel – with the new regulations having seen the previous lap record, 1.32.238, set by Schumacher in 2004, comprehensively demolished. The top four were separated by less than four-tenths and clearly the pace Ferrari showed in Australia was not a one-off peculiar to Albert Park.

Vettel had gone fastest in the first session and Raikkonen in the second, but when it mattered Hamilton had the edge. He briefly lost the rear at turn 11 on his first hot lap in Q3 and did well to hold it, which cost him time. But he had still done enough to go quickest, one-tenth clear of Vettel, and quickly went one better, this time with an error-free run that secured the 75th pole for Mercedes.

Felipe Massa was the best of the midfield qualifiers, for Williams in sixth, while Nico Hülkenberg produced a storming lap to put his relatively uncompetitive Renault into seventh. The Force India of Sergio Pérez was in eighth, with the Toro Rosso of Daniil Kvyat, and Lance Stroll in the second Williams – putting in a very solid run in his debut season – rounding out the top 10.

Carlos Sainz Jr in the Toro Rosso just missed the final session, going out in Q2 in 11th, followed by the Haas of Kevin Magnussen. Fernando Alonso had done another extraordinary job to put his McLaren into tenth in Q1, and briefly looked like he might wrestle it into the top 10 again. But the Spaniard could not quite manage it, ultimately ending in 13th place, in front of the Sauber of Marcus Ericsson.

Sauber ran with the third Ferrari driver, Antonio Giovinazzi, again standing in for Pascal Wehrlein, but he lost the car on the exit of the final turn in Q1 and put it in the wall at the end of the session, which looked to have affected the final laps of several drivers.

However, Haas’s Romain Grosjean and Jolyon Palmer in the Renault were adjudged to have not backed off sufficiently under double waved yellow flags after the incident and took five-place grid penalties, meaning they will start from 19th and 20th respectively, although Palmer insisted he had slowed.

McLaren’s Stoffel Vandoorne finished 16th while the time Giovinazzi had already set was enough to secure him a place in Q2 although he took no part in the session. He will start from 15th, and Force India’s Esteban Ocon will begin 18th.