The FP3 Quartararo pacemaker set the initial pace with 1m37.064s, which was immediately defeated by Marquez with 1m37.006s.
The Petronas Yamaha rider plunged under the 1m37s barrier on his second lap to claim the provisional pole with 1m36.993s, while Francesco Bagnaia de Pramac put his Ducati in third place despite encountering a slower Valentino Rossi at the last corner.
Marquez returned to first place with a. 1m36.877s on his first lap of his second run, although Maverick Vinales outclassed him, who put in a blinding final sector to finish with a 1m36.844s.
With about a minute to go, Pramac’s Jack Miller was on a challenging lap for pole, but suffered a quick crash at Turn 11.
A few seconds later, Alex Rins crashed in the same spot and had to be helped into the ambulance while holding his wrist.
In the midst of the drama, Quartararo produced 1m36.705s to plunge below the lap record he set in FP3 and secure his second consecutive pole position at Jerez.
Vinales remained in second place, with Marquez completing the front row ahead of Bagnaia, whose fourth place is the best qualifying result of his career.
Miller will start alongside despite their clash in fifth place, with LCR Honda’s Cal Crutchlow just 0.001s behind him in sixth.
Pol Espargaró passed Q1 alongside Rins and put his seventh KTM ahead of Andrea Dovizioso’s Ducati factory, who fell at Turn 2 at the end.
Rins was ninth, although his start now seems doubtful, while Franco Morbidelli (Petronas), Rossi and Joan Mir (Suzuki) completed the top 12.
Brad Binder briefly had the fastest time in Q1, and finally qualified an impressive 13th for his MotoGP debut in KTM, as he only missed one place in Q2 by just 0.138s.
The 2016 Moto3 world champion beat Ducati of Danilo Petrucci, with Takaaki Nakagami in 15th place in his one-year LCR Honda.
Aleix Espargaró was Aprilia’s best in 16th place, while teammate Bradley Smith was 18th after suffering a crash at Turn 2 in the final stages.
Johann Zarco also suffered a fall at the end, which stopped the Avintia Ducati rider advancing in his 20th position ahead of Honda rookie Alex Marquez and Iker Lecuona’s Tech3 KTM.