Julian Alvarez scored early for Pep Guardiola’s side following a blunder, before Pierre-Emerick Aubameyang and Frenkie de Jong scored 2-1 to the hosts.
Cole Palmer scored an equalizer, but Memphis Depay headed in a cross to give Barcelona the advantage again.
Deep in stoppage time, Erling Haaland was awarded a penalty, which Mahrez scored.
Due to Covid’s attendance limits, the charity game that was supposed to take place last summer was postponed.
READ MORE: Newcastle are set to sign Swedish striker Alexander Isak
It had been planned to raise money for ALS awareness in memory of Juan Carlos Unzue, a former Barcelona player and coach, given the diagnosis just over two years ago.
Saturday’s Premier League match between Guardiola’s team and Crystal Palace features a strong lineup, including summer acquisitions Kalvin Phillips, Phil Foden, and Bernardo Silva, which Barcelona is reportedly pursuing.
Rafinha, a former Leeds player, started for the Spanish powerhouses, along with Franck Kessie, a midfielder, and Jules Kounde, a defender who has yet to register for the La Liga due to wage cap restrictions.
Depay’s late goal appeared to have won the game in front of 91,062 spectators, but Mahrez equalized from the spot in the tenth of the extra 11 minutes after Luke Mbete of City suffered an injury.