An own goal from former Barca player Mark van Bommel, a Lionel Messi penalty and Xavi gave the title holders victory in a thrilling game.
Although largely outplayed Milan, who were already guaranteed second place in the group, fought gamely and replied through another former Barcelona player Zlatan Ibrahimovic and a wonderful goal from Kevin-Prince Boateng.
But the Spaniards left no doubt as to who the better team was with a scintillating performance full of verve, quick passing, incision and energy.
And although they conceded two goals, coach Pep Guardiola said there was no shame in that against a team of Milan’s stature.
“We can’t expect to come here to the San Siro and not be put in some difficulty,” he said.
“If we wanted to play more conservatively we would take out an attacker and play an extra defender.
“Other than the opportunities Milan created, which is normal given their quality and they team they are, we can also talk of the chances we created.”
Goalscorer Boateng felt his team had more than matched Barca.
“It was a good game, we were unlucky but the most important thing is that we’ve qualified,” he said.
“Barcelona are the best team in the world but we played really well and when everyone’s concentrating we can match anyone.”
Milan coach Massimiliano Allegri felt this was a good learning curve for his players.
“It was important to play a match such as this to see what stage we’re at,” he said.
Barca gave an early sign of things to come as Thiago Alcantara stepped over a Messi pass to free David Villa but the Spain striker’s finish was woefully high.
The visitors took the lead on 14 minutes as they strung the passes together again and Messi found Seydou Keita in acres of space on the left side of the area with his devilish cross into the six-yard box being turned in by the unfortunate Van Bommel.
Another great move saw Thiago’s flick put in Cesc Fabregas, whose powerful shot hit goalkeeper Christian Abbiati.
Milan should have been level when a cross from Ibrahimovic found Boateng at the back post and his mishit shot fell to Robinho inside the six-yard box but the Brazilian embarrassingly lifted the ball over the bar.
Milan kept pushing and Clarence Seedorf played in Ibrahimovic in the inside left channel and his finish crept under Victor Valdes on 20 minutes.
That turned out to be a false dawn as Barca stepped up the pace.
Xavi passed to Fabregas who crossed for Messi but he proved unusually human and his shot from six yards deflected off Abbiati and onto the bar.
A Xavi free-kick found Villa but his free header went well off target.
Barca were awarded a seemingly generous penalty when Alberto Aquilani bundled over Xavi in the box and Messi, who was booked for stopping in his run-up when scoring at the first time of asking, duly fired home on the second take.
A stunning run from the Argentine wizard then saw him beat four players but Abbiati was equal to his shot.
The second half saw no let up from Barca as Fabregas chipped over the defence but Messi shot into the side-netting.
Out of nothing Milan equalised again after Boateng played a Messi-esque flick to leave Eric Abidal standing and thrashed his shot past Valdes at his near post.
But again Barca carved open the Italian champions as a stunning pass from Messi picked out Xavi and his 64th-minute finish was precise.