Quartararo was a comfortable winner, and Espargaro looked nailed on for second place as he began the final lap, but the Spaniard thought the race was over and began waving to the crowd in Barcelona.
He was celebrating what he believed to be a podium finish, having started in pole position, but by slowing down he lost momentum and could not recover once he realised his clanger, trailing home in fifth.
Espargaro would have had good cause to celebrate second place, given he suffered abandonments in six of his previous seven appearances in this race, finishing only once when he was 12th in 2020.
The devastated Espargaro was later seen with his head in his hands by the side of the track and in the Aprilia garage. Nine points had slipped away, potentially crucial come the end of the season, with Quartararo boosting his championship lead to 22 points.
Quartararo and Espargaro were first and second at halfway, with a gap of around four seconds between the pair.
Espargaro slipped a place as Jorge Martin jumped to second, but the Aprilia man soon edged back ahead of the Pramac rider.
There had also been early drama, with Francesco Bagnaia (Ducati), winner of two of the last three races this season, crashing out on the first corner along with Takaaki Nakagami (LCR Honda) and Alex Rins (Suzuki Ecstar) after a shunt.
Enea Bastianini (Gresini), third in the championship, a place ahead of Bagnaia, also tumbled out of the race, with Quartararo's grip on first place tightening even before Espargaro's hapless error.
1. Fabio Quartararo (Monster Energy Yamaha)
2. Jorge Martin (Pramac Racing) +6.473 seconds
3. Johann Zarco (Pramac Racing) +8.385s
4. Joan Mir (Suzuki Ecstar) +11.481s
5. Aleix Espargaro (Aprilia Racing) +14.395
6. Luca Marini (Mooney VR46) +15.430
7. Maverick Vinales (Aprilia Racing) +15.975
8. Brad Binder (Red Bull KTM) +21.436
9. Miguel Oliveira (Red Bull KTM) +26.800
10. Alex Marquez (LCR Honda) +30.460
1. Fabio Quartararo (Monster Energy Yamaha) 147
2. Aleix Espargaro (Aprilia Racing) 125
3. Enea Bastianini (Gresini Racing) 94
4. Johann Zarco (Pramac Racing) 91
5. Francesco Bagnaia (Ducati) 81
1. Aprilia Racing 171
2. Monster Energy Yamaha 169
3. Ducati Lenovo 146
4. Pramac Racing 142
5. Suzuki Ecstar 138