A surprise Ferrari one-two resulted in Charles Leclerc on pole position and Carlos Sainz in second after a thrilling Q3 in Mexico.