Milan twice came from behind, through Ibrahimovic and a stunning Kevin-Prince Boateng effort, as they replied to a Mark van Bommel own goal and a twice-taken Lionel Messi penalty in a match which was little more than a friendly.
Both teams had already qualified for the last 16 with two matches to spare. Barcelona's win put them five points clear at the top of Group H and ensured they would finish in first place.
There was an element of controversy about Messi's goal and his first effort was disallowed because he stopped at the end of his run-up and feigned to kick the ball - a practice recently outlawed by FIFA.
The Argentine was booked for his trouble but he still dispatched the second penalty shot with ease.
Xavi's 63rd-minute winner had Barcelona written all over it.
Messi managed to pick out the playmaker with a measured diagonal pass which he slipped between four Milan defenders. Xavi took the pass in his stride and slotted past Christian Abbiati.
His strike came nine minutes after the best goal of the evening when Milan's Boateng collected a high pass from Ibrahimovic, flicked the ball past the legs of the bemused Eric Abidal and found a gap between Victor Valdes and the near post.
Barcelona remain unbeaten this season in all competitions, although coach Pep Guardiola's response was muted.
"We had a lot of possession and created a lot of chances," he said. "It is important to have won here, Milan were happy with their performance, so we are all happy."
Milan coach Massimiliano Allegri, whose side have won five and drawn one of their last Serie A matches, admitted his team's finishing let them down.
"I think we played well although we made some mistakes, we should have made more of our chances but our self-confidence is higher and we know we can compete in these Champions League matches."
Barca enjoyed 64 percent of the possession in the first half and it was little surprise when they went ahead in the 14th minute.
Messi found Seydou Keita at the far post and the Malian's low ball back across was turned into his own goal by Van Bommel.
Milan occasionally looked dangerous and, after Robinho missed a glaring chance from close range by scooping the ball over an open goal, Ibrahimovic levelled with he turned Seedorf's pass beyond Valdes.
The Swede, less than amused when he was offloaded by Barcelona after the 2009/10 season, celebrated discreetly.
Barca regained the lead in the 31st minute with Messi's penalty, harshly awarded after Xavi crumbled when he was struck by Alberto Aquilani's arms.
Boateng levelled nine minutes after the restart but, not to be outdone, Barca replied with Xavi's effort.
Get the best features, fun and footballing frolics straight to your inbox every week.
Thank you for signing up to Four Four Two. You will receive a verification email shortly.
There was a problem. Please refresh the page and try again.