Xavi Hernandez ran onto Lionel Messi’s perfect pass into the area to slot in the winning goal in the 63rd minute, sealing the group win with one game remaining.

Both teams had already qualified for the knockout stages, which may have contributed to their willingness to attack throughout in a game that easily could have had an even bigger scoreline.

Milan midfielder Mark van Bommel gave Barcelona the lead in the 14th minute with an own goal and, despite Ibrahimovic’s leveler, Lionel Messi’s twice-taken penalty ensured the defending champions went into the break in front.

Kevin-Prince Boateng pounced in the 54th to get Milan back into the game, but Messi slotted the ball through a throng of defenders for Xavi to seal the win.

Much of the pre-game talk had focused on Ibrahimovic, who faced his former club for the first time since his acrimonious departure in 2010 after falling out with Barcelona coach Pep Guardiola following his only season in Spain. While the Sweden striker did get a goal, it was still Barcelona who stole most of the spotlight with their usual relentless attacking play.

The Spanish club extended its unbeaten streak to 27 competitive matches since losing to Real Madrid in the Copa del Rey final, one short of the team record set from September to January last season.

Barcelona should have gone in front in the fourth minute when an unmarked David Villa blazed over from the edge of the box. Seconds later Xavi tried to pick out Thiago Alcantara but his pass was just too long for the young midfielder.

Milan had its best chance of the opening exchanges in the 11th minute when Ibrahimovic nodded Gianluca Zambrotta’s free kick over to Robinho but goalkeeper Victor Valdes gathered the ball just in time.

Barca was ahead shortly afterward when Messi crossed the ball to Seydou Keita, whose pass across goal was turned into is own net by the unfortunate Van Bommel.

Guardiola’s men almost doubled their lead moments later but Ignazio Abate did well to snatch the ball off Messi following a swift one-two with Cesc Fabregas.

Robinho made a glaring mistake when he fired Boateng’s cross over the bar from close range, but the Brazilian’s blushes were spared to some extent moments later when Milan leveled. Clarence Seedorf threaded the ball through for Ibrahimovic to slot past Valdes and into the bottom left corner from 10 yards out for his fourth goal in four Champions League games this season.

Ibrahimovic scored 16 goals in the Spanish league but often struggled to fit into Barcelona’s intricate passing schemes.

Barcelona almost immediately restored its lead in the 23rd minute as Messi set up Fabregas but the former Arsenal playmaker crashed his effort off the crossbar from close range.

But the Spanish club was back in front shortly after the half hour mark when Xavi went down lightly under Alberto Aquilani’s challenge in the area. Messi sent Abbiati the wrong way with a soft penalty straight down the middle, but the Argentine was ordered to retake his spot kick after pausing just before striking the ball.

Messi’s second penalty was much more emphatic, straight into bottom right corner, giving Abbiati no chance even though he dived the right way.

It was almost worse for Milan seconds later as Villa raced onto Messi’s pass but lofted his shot just the wrong side of the crossbar.

Barcelona had further chances to extend its lead at the start of the second half as both Messi and Villa saw shots go just the wrong side of the left upright.

It was left to rue those missed opportunities in the 54th when the ball fell to Boateng in the area, who downed it with one touch before rounding his marker with a neat backheel flick and slotting the ball past Valdes and into the bottom right corner.