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.
Mario Balotelli scored direct from a free kick and substitute Giampaolo Pazzini hooked in from a corner to give Milan a second successive 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 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 began after the Indonesian business tycoon’s consortium completed its takeover of the club in November.
Alberto Aquilani scored a hat-trick for fourth-placed Fiorentina but it was not enough for victory as they were held 3-3 at home by Genoa.
Roma have 50 points from 21 games and moved within six of leaders Juventus, who were held 1-1 at Lazio on Saturday.
Inter are fifth with 33 points, one ahead of Parma, Torino and 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 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.
“It wasn’t always pretty to watch but the wind made it difficult to play well,” Seedorf told reporters. “We are working on improving matters, but the most important thing was to rediscover mental strength and courage, which we saw today.”
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.
Genoa went ahead in the late game when Alberto Gilardino converted a harshly-awarded penalty in the 27th minute only for Aquilani to equalise six minutes later from an equally controversial spot kick.
Luca Antonini put Genoa back in front one minute later, but Aquilani to levelled again before halftime.
The former Liverpool, Milan and Juventus forward put Fiorentina ahead for the first time with an angled drive but Genoa grabbed a point after Fiorentina failed to clear a corner and Sebastien De Maio scored from close range in the 77th minute.
(Reporting by Brian Homewood; Editing by Ed Osmond)