A year on from losing a podium on home soil for miscounting how many laps he had remaining, Espargaro made up for this by beating world champion Bagnaia by just under two seconds.
Strong all weekend at Barcelona, Espargaro ran fourth on the opening lap having dropped from second on the grid but would take the lead on lap seven.
Easing away from Bagnaia, Espargaro came under no trouble as he took the chequered flag for his second win of the 2023 MotoGP season.
Bagnaia fended off the sister factory Aprilia of Maverick Vinales over the remaining laps to secure runner-up spot by just 0.051s.
Just as he did in Austria, Bagnaia converted pole to the holeshot as Vinales proved his start woes had been fixed by rocketing into second.
Pramac Ducati rider Jorge Martin slotted into third ahead of Espargaro, but by the start of lap two the latter have moved up to second.
Bagnaia pushed early on and built a lead of 0.5s come the end of the second tour, but Espargaro quickly closed him down.
Close to several attempts into Turn 1 over the next few laps, Espargaro’s decisive move came on lap seven.
Utilising the turning capabilities of the RS-GP to launch onto the main straight, he was able to draw alongside Bagnaia and outbrake him into Turn 1.
Espargaro would take the chequered flag 1.9s up the road from Bagnaia, who quickly dropped off the rear of the Aprilia rider.
Vinales completed the podium behind Bagnaia, with Brad Binder just out of touch in fourth on his KTM.
Martin dropped back to his starting spot of fifth ahead of RNF Aprilia’s Miguel Oliveira, with Johann Zarco seventh on the sister Pramac bike.
Marco Bezzecchi was eighth on his VR46 Ducati, with the factory Ducati of Enea Bastianini taking the final point in ninth.
Alex Marquez missed out on points in 10th on his Gresini Ducati, as Honda-mounted brother Marc Marquez was 11th after running wide late on while ahead.
Fabio Quartararo’s difficult day continued as the Yamaha rider struggled to 18th as team-mate Franco Morbidelli took 15th from KTM’s Jack Miller.
Tech3’s Pol Espargaro was the only crasher as he took a tumble at Turn 5 when he ran wide onto the gravel on lap four.
Despite losing out to Aleix Espargaro, Bagnaia’s championship lead has extended to 66 points.