Bagnaia denies returning Marquez to take French MotoGP pole
Six-time world champion Marquez was heading for the front of the grid on his return from injury sustained in a first lap crash in the season-opener in Portugal.
But the 30-year-old Spaniard was bettered by just 0.058sec by Bagnaia's final flying lap to leave the Ducati rider heading the grid for both Saturday's sprint and Sunday's main event.
"It wasn't easy, everything went well, I'm very happy, it was a great lap time," said Bagnaia, seeking his third sprint win of the campaign.
Honda's Marquez was thrilled to be back in the heart of the action after claiming pole position in Portugal only to then break his hand in the crash on race day.
A fifth surgery in three years followed and he sat out the following rounds in Argentina, United States and Jerez.
He commented: "My target today was really to be on the third row, but I'm on the front so I did something amazing. I had a better feeling with my bike than yesterday."
He added: "Starting from the front row is much easier, but the main aim this weekend is to try to show speed and put together a series of fast laps in a row against the Ducatis."
Joining this pair on the front row of the grid for the fifth round of the season is Luca Marini for Valentino Rossi's Ducati-VR46 team.
Marini did well after having to come through the first qualifying repechage session where only the first two riders go through to the shoot out for the first four rows of the grid.
Missing out though was 2021 world champion Fabio Quartararo.
The Frenchman failed to make his struggling Yamaha fire and he will start both the sprint and the race back on the fifth row in front of his home fans.
Aleix Espargaro had a lucky escape when walking away unharmed from a near 300kph crash, his Aprilia bike bouncing to a rest in the gravel safety pit.
Bagnaia leads the MotoGP standings by 22 points over fellow Ducati rider Marco Bezzecchi after two sprint and two race wins.
But the Italian has a poor record in France, with his best showing a fourth from four appearances. Last year he crashed after setting off from pole.
Jack Miller, who had cut a dash on his KTM in both practice sessions on Friday, came fourth to occupy the second row with Spanish duo Jorge Martin (Ducati-Pramac) and Maverick Vinales (Aprilia).
Bezzecchi posted the seventh best time and keeping the Italian company on the third row are Marquez's younger brother Alex (Ducati-Gresini) and France's Johann Zarco (Ducati-Pramac).
South Africa's Brad Binder, third in the overall standings, starts from the fourth row alongside crash-victim Espargaro and Augusto Fernandez.
Saturday's sprint is staged over half the distance of Sunday's grand prix with half points awarded.