The European champions took the lead after 15 minutes when Mark van Bommel put through his own net from Seydou Keita's shot.
The Italian side were level five minutes later when former Barca striker Zlatan Ibrahimovic lifted the ball over goalkeeper Victor Valdes from inside the area.
Barcelona were back in front on 30 minutes when Lionel Messi struck from the penalty spot. The Argentine forward had to retake his kick, but he lashed the ball down the centre of the net past Christian Abbiati.
Milan squared the match ten minutes after the break when Kevin-Prince Boateng fired into the Barca goal.
However, the visitors regained the lead soon after when Xavi Hernandez collected Messi's pass to slot home.