Mario Balotelli won the game for Italy with a 78th minute goal after Pirlo's majestic effort had put them ahead and Javier Hernandez levelled for Mexico with a penalty.
The match was again played against the backdrop of teargas and rubber bullets as riot police confronted protesters outside the Maracana stadium.
A similar demonstration had marred Saturday's opening match between hosts Brazil and Japan in Brasilia. The protests are against the amount of public money being spent on staging the event and next year's World Cup.
Balotelli had a couple of early chances for Italy while Mexico's Andres Guardado shaved the crossbar after a mistake by Ignazio Abete in a lively start.
Pirlo, always at the heart of the action, had a penalty turned down before bringing the Maracana to its feet with his 27th minute goal.
Mexico levelled seven minutes later when Andrea Barzagli was dispossessed by Giovani dos Santos and then barged over the Mexican forward as he tried to atone for his mistake. Hernandez sent Gianluigi Buffon the wrong way from the penalty spot.
Pirlo then produced outrageous reverse pass to release Abete on the right, the move ending when Balotelli's effort was blocked by Jose Corona from Abete's low cross.
Pirlo's free kicks continued to cause trouble after the break and he curled another effort just wide of the post from a similar position to his goal.
Italy grabbed the winner when Emanuele Giaccherini cleverly flicked the ball into the penalty area where Balotelli held off Francisco Rodriguez and fired the ball past Corona.
(For more sports news and updates, follow Ahram Online Sports on Twitter at @AO Sports and on Facebook at AhramOnlineSports)