Red Bull appeared to be favourites for pole after Verstappen headed Hamilton in both of the first two sessions of qualifying.
Perez, on excellent form and pretty much a match for Verstappen for once all weekend, then set the pace on the first runs in the final session, ahead of Verstappen, Bottas and Hamilton.
The seven-time champion went out early for his final run and pulled out an excellent lap to leap ahead of the Red Bulls, but Verstappen proved too strong to reclaim the place on his final lap.