The Catalan club came out on top in a breathtaking encounter, with the World Cup winner's second-half strike securing all three points for the visitors
The Catalans took the lead in the 14th minute thanks to an own goal from Mark van Bommel before Zlatan Ibrahimovic equalised seven minutes later. Lionel Messi's penalty gave the visitors the lead just after the half-hour mark, yet a wonderful individual effort from Kevin-Prince Boateng levelled matters once again.
However, Xavi popped up to score what proved to be the winning goal and collect the points for Pep Guardiola's outfit.
After an opening period where both sides assessed each other from distance, Barcelona took the ascendancy, and the lead, on 14 minutes with the first real attack of the game. Messi's clever ball found Seydou Keita in space inside the box before the Malian played a low cross which was bundled into his own net by Van Bommel.
Milan should have equalised immediately in the 19th minute, but Robinho was guilty of a shocking miss. Ibrahimovic's cross into the box was drilled into the direction of the unmarked Brazilian forward who smashed over the crossbar from close range.
However, the home team were level two minutes later, taking advantage of some slack Barca defending. Clarence Seedorf's clever pass bypassed the visitor's defence as Ibrahimovic was allowed to slot the ball home from 10 yards out.
Guardiola's men had a glorious chance to re-take the lead on 23 minutes and it was Messi's turn to squander a glaring opportunity. Cesc Fabregas did well to work some space on the right side of the penalty area before sliding the ball to the Argentine, who struck the top of the bar on the run.
His miss was a mere warning, as Barca were awarded a penalty on the half hour mark when Alberto Aquilani was guilty of pulling down Xavi in the box. Messi stepped up to put the ball in the far corner, beyond the outstretched hand of Christian Abbiati - the second time the Argentine had found the back of the net in a minute after the referee ordered a re-take.
The second half commenced in equalling pulsating fashion, and although the away team made the brighter start in the second period, Milan found themselves level again on 54 minutes through a moment of brilliance from Boateng.
The Ghana international seized on a loose ball on the edge of the box before sending Eric Abidal the wrong way with a clever touch using his heel. Faced one-on-one with Victor Valdes, the midfielder slammed the ball low past the goalkeeper at his near post from 12 yards out.
For the third time in the game, Guardiola's side were back in front on 63 minutes with another beautifully taken goal. Fabregas and Messi linked well before the Argentine slid a precise through ball to Xavi, who calmly placed his shot into the bottom corner in what proved to be the winning goal of the game.
The victory ensures that the European champions will progress as group winners, while Milan's place in second was already secured prior to kick-off. Both sides round off their respective campaigns on December 6 when Barcelona entertain BATE Borisov, while Milan face Viktoria Plzen.