Marco Borriello came back to haunt his former employers scoring the only goal of the game, although in somewhat fortuitous circumstances.
Milan were the better side throughout but Roma defended stubbornly and held firm to snatch the three points.
And ironically it was the man Borriello was shipped out to make spce for -- Zlatan Ibrahimovic -- who missed three gilt-edged chances to get Milan something out of the game.
But the victory, according to Ranieri, has lifted Roma's morale.
"Of course a win against the league leaders means a lot, if we'd have lost we'd have suffered a notable psychological blow," he said.
"Winning has kept us alive, although we're aware of our difficulties.
"This is a serious group that gets angry when things don't go the way they should, we're a compact group.
"I was happy with our patience without getting pushed back and beating off attack after attack.
"The pleasure for me is seeing my team win and the fans happy."
Ranieri also heaped praise on goalkeeper Doni who made a crucial one-on-one save to deny Ibrahimovic.
Doni spent years as Roma's first choice stopper but has dropped down the pecking order this season and was playing only due to injuries to Julio Sergio and Bogdan Lobont.
"The defence did well but you also have to praise Doni who saved us in the first half with this one-on-one save againist Ibrahimovic," said Ranieri.
"We were compact, we knew how to suffer in the difficult moments and then to attack from deep.
"It's not easy to create more against Milan, who are so mobile and deserve to be top."
Ranieri sprung a surprise by dropping club captain Francesco Totti to the bench and giving Adriano a rare start, but the Brazilian played his part in providing a physical presence up front.
"I'm very happy for Adriano and I'm sure he'll give us even more satisfaction in the new year," added Ranieri.
"I'm paid to make choices and I assume my responsibilities. But if Doni hadn't made this wonderful save against Ibra then we would be speaking of other things."
Milan coach Massimiliano Allegri admitted his team were far from their best and complained that they had not be clinical enough.
"As we didn't play particularly well we deserved only a draw but when you're not nasty enough in the right moments, these things can happen," he said
"That certainly wasn't the team of last Sunday (in the 3-0 win at Bologna)."
However he pointed to the fact that they will still be top as Serie A shuts down for its winter break as they came into this game with a six point lead at the top.
"We're disappointed we've lost at home but we still have to be happy with what we're doing.
"Now we'll see what the others do, we'll still finish the year top and that's a good result.
"And I'll ask the players for more of the same in 2011."
The winning goal came on 69 minutes with French winger Jeremy Menez the architect, darting to the byline down the right and knocking in a dangerous cross which full-back Ignazio Abate, in trying to clear his lines, succeeded only in thumping off Borriello's shins and into the net.
The win closed Roma's gap to Milan to seven points and ensures they are still well in the title race.
The result will also have been greeted with cheers by champions Inter Milan - who won the Club World Cup on Saturday - as they too could close their deficit to Milan to seven points if they win the two games in hand they missed while out in Abu Dhabi.