Roma and Milan had both dropped to seven points behind Juventus after Gonzalo Higuain scored twice on Sunday to seal a precious 2-1 derby win at Torino.
AC Milan coach Vincenzo Montella was welcomed back to the stadium where he played many memorable games as a forward for the Giallorossi, celebrating his goals doing the 'Aeroplanino' (Little Airplane).
But it was Luciano Spalletti's hosts who were left celebrating following an entertaining clash, Nainggolan beating Milan's teenaged 'keeper Gianluigi Donnarumma in the 62nd minute to make it three wins in succession.
Roma remain second, four points off the lead with Milan seven adrift in third, with a one-point lead on both Napoli and Lazio.
"It was a difficult game tonight because Milan have quality throughout the squad," Spalletti told Mediaset.
"What they say about this team and their coach is true. They're up there with the best and they'll be fighting to the end.
"We did well to take the three points."
After just 20 minutes Gianluca Lapadula earned Milan's chance when he tempted Wojciech Szczesny into a rash tackle.
But when Niang stepped up to take it, fans had reason for concern.
Last week the Frenchman was involved in an on-field spat with Lapadula after his fellow forward had won a penalty at Crotone. Niang won the argument, but missed the penalty and it was thanks to Lapadula's late winner that Milan took the points from a 2-1 win.
This time these was no spat, but Niang's tame shot was well covered by Szczesny, who dived to his left to parry it to safety.
Montella later said: "They say Milan get lucky sometimes. Well, not tonight.
"But there were a lot of positives tonight, it wouldn't be fair to focus on just one incident."
Later Szczesny laughed off his heroics: "I was just doing my job. I'd made an error so was trying to remedy it."
After the miss, Roma took the initiative, striker Edin Dzeko firing an angled drive inches past Donnarumma's post, but Spalletti was left concerned when Bruno Peres was stretchered off in tears to be replaced by former Milan star Stephan El Shaarawy.
Milan resumed in far more positive fashion after the break, but Mario Pasalic was off target from Andrea Bertolacci's delivery.
And after Diego Perotti blasted over from a corner for the hosts, Nainggolan cut in from the right to unleash a left-foot drive from outside the area that left Donnarumma clutching at thin air.
Roma could have doubled their lead but Donnarumma did well to stop Dzeko's drive at the near post after the Bosnian robbed Gabriel Paletta, while at the other end Mati Fernandez failed to trouble Szczesny with a shot at the neat post.
Earlier, Croatia striker Nikola Kalinic struck a stunning first-half brace as Fiorentina held off a spirited fightback from Sassuolo to prevail 2-1 and move up to seventh.
La Viola settled quickly at their Artemio Franchi stadium and after Josip Ilicic curled an early free kick inches past the top corner, they had a 10th minute lead.
Ilicic was involved again with another free kick, but after it hit the wall to bounce up into the air Kalinic stole the glory with a spectacular volley to beat Andrea Consigli in the Sassuolo net.
Remarkably, it was Kalinic's first goal at home since against Juventus last April, the Croatian scoring all six of his previous goals this term away.
Five minutes before the interval, Kalinic produced another sparkler, the striker meeting Federico Chiesa's low cross with a cheeky back-heel flick from the edge of the box that bounced in off the inside of the upright.
Sassuolo reduced arrears three minutes later, Acerbi firing home from a crowded area as the hosts failed to deal with a corner on 75 minutes.
Updated Date: Dec 13, 2016 14:53:14 IST