Bottas took provisional pole by just 0.007 seconds over Hamilton after their first laps, but the first sector of the Finn’s final lap was poor, handing the advantage to his teammate.
However, the Briton put in a poor last sector of his own, handing the initiative back to Bottas, who inched open his advantage to 0.023 seconds to claim his first pole of the season.
“It’s been a good weekend so far,” championship leader Bottas beamed. “Honestly struggled a bit in Q3 to get the perfect lap in, but it was good enough.
“The lap was okay… not completely how I wanted, but luckily it was good enough for pole.”
It was a strong performance not only for Bottas, who endured a patchy weekend in Bahrain last round, but also Mercedes, which expected to struggle against Ferrari on the Shanghai International Circuit’s long straights.
Hamilton in particular struggled to find a rhythm inside the car for much of the weekend, but the reigning title-holder credited his team for clearing the path to claiming the 59th Mercedes front-row lockout.
“[Ferrari] are particularly quick on the straights, but it’s evident this weekend we’ve managed to pull some performance from the corners,” he said.
“I’ve been struggling and fighting the car all weekend.
“It was 0.8 at one stage, so to be as close as we are at the end is fantastic. It’s an incredible result for the team.”
Ferrari teammates Sebastian Vettel and Charles Leclerc fought hard for third and fourth places, the more experienced German edging his young Monegasque teammate by just 0.017 seconds.
Vettel admitted his car didn’t have the expected pace to match Mercedes, but he remained optimistic that the race win was in his grasp.
“Right from Q1 they just seemed to start off from a better place,” he said. “I think there was maybe a little bit more, but not enough to beat these guys today
“They are bloody quick in the corners… but for us when we get close we have an advantage in a straight line, so maybe we can do something there.
“The race is long, we take it from there – it should be a good day tomorrow.”
Chaos reigned behind the fight for pole as drivers jostled for track position to start their final flying laps, but it cost some dearly, with both Red Bull Racing drivers and both Haas drivers crossing the line too late to set a time.
The embarrassing mistake locked Max Verstappen into fifth ahead of Pierre Gasly with a 0.8-second advantage, while Kevin Magnussen and Romain Grosjean were stuck in ninth and tenth.
Renault drivers Daniel Ricciardo and Nico Hulkenberg fought among themselves for seventh and eighth, the Australian qualifying ahead of the German.
The top three teams were in a league of their own, using the medium-compound tyre to make it through to the top-10 shootout, but behind them the midfield scrap was tight for a spot in Q3.
Renault and Haas squeezed through, but it was close – just 0.022 seconds separated Daniil Kvyat in 11th from the safety of 10th place.
The order of cars from 11th to 14th – excluding Lando Norris’s unusually slow lap in his McLaren, leaving him 15th – was separated by less than 0.3 seconds.
Slotting in behind 11th-placed Kvyat was Racing Point’s Sergio Perez, while Alfa Romeo’s Kimi Raikkonen, who complained of a power cut on his final lap costing him time.
Carlos Sainz qualified 14th ahead of McLaren teammate Norris.
Avoiding a bottom-five elimination from qualifying was made easier by the non-starting Alex Albon and Antonio Giovinazzi, neither of whom set a time.
Thai driver Albon was without his car after crashing heavily at the end of Saturday morning practice just two hours before the start of qualifying. He emerged unscathed, but the rear of his car was mangled beyond recognition, forcing him to start from the pit lane on Sunday.
Giovinazzi, on the other hand, sat in his car while his team attempted to repair an unspecified technical problem. The Italian lost 90 minutes of practice on Friday morning after his engine was installed incorrectly, and his failure to set a qualifying time only compounded his misery.
Their absences left just three drivers at risk, and with the slow Williams cars guaranteed 17th and 18th on the grid, only one among the midfielders would be knocked out early.
Racing Point, which had been struggling for pace all weekend, proved the slowest car, and Lance Stroll was the man to lose out, qualifying 16th.
Don’t forget to listen to Live89.5 each and every Saturday at 9am and 5pm for the Box of Neutrals radio show.