Mario Balotelli scored direct from a free kick and substitute Giampaolo Pazzini hooked in from a corner to give Milan their second straight Serie A win since their former player Clarence Seedorf took over as coach.
Inter, with new club president Erick Thohir making a rare appearance at San Siro, dominated possession but created few real chances, further angering their already restless fans who greeted the team bus with jeers outside the ground.
Inter have won only one of their last nine Serie A games, a run which coincidentally began after the Indonesian business tycoon's consortium completed its takeover of the club in November.
Roma have 50 points from 21 games and moved within six of leaders Juventus, who where held 1-1 at Lazio on Saturday.
Inter are fifth with 33 points, only one ahead of Parma, Torino and Hellas Verona while Milan climbed to ninth with 28 points.
Milan gifted Cagliari the lead on a blustery afternoon in Sardinia when goalkeeper Marco Amelia sent a clearance straight to Mauricio Pinillia, who curled the ball into the area for Marco Sau to score with a classy finish.
With the Sant'Elia stadium still being rebuilt, only 4,500 fans were able to watch the match, nearly all of them packed behind one goal, creating an unusual atmosphere.
Cagliari, only four points clear of the relegation zone, sat back on their lead in the second half and paid the price in the last five minutes.
Balotelli, whose late penalty gave Seedorf a winning start against Hellas Verona last week, curled a free kick past a poorly-placed wall and into the net in the 87th minute after a needless handball by Matias Cabrera.
The hosts were all at sea and more shoddy defending allowed Pazzini to hook in from a corner two minutes later.
Gervinho set up Roma's first goal with a surging run down the left before pulling the ball back for Adem Ljajic, who tapped in from close range.
Emil Hallfredsson fired the equaliser after the break but Gervinho put Roma back in front on the hour when he collected the ball in the penalty area, skipped past two defenders and scored with a low shot through a crowd of players
Francesco Totti wrapped up the three points by converting a controversial penalty.
Amauri's first-half goal gave Parma a 1-0 win over Udinese, pushing their opponents further towards the relegation zone, while Torino beat Atalanta by the same score thanks to an Alessio Cerci penalty on the hour.
Livorno scored three times in the first half hour on their way to beating Sassuolo 3-1 in a clash featuring two teams mired in the danger zone.
Alessandro Diamanti's last-minute penalty gave Bologna, hovering just above the bottom three, a 1-1 draw and a precious point at Sampdoria.
- Sports & Recreation
- Hellas Verona
- Clarence Seedorf
- Mario Balotelli
- Giampaolo Pazzini