Rome:AC Milan scraped a 2-1 victory at Cagliari as a stunning Andrea Pirlo free-kick five minutes from time stole the points.
Milan were out of sorts despite Brazil star Ronaldo making his first appearance of the season and could easily have lost the match.
Instead they rose to ninth in the Serie A table and closed the gap on city rivals Inter Milan at the top to 11 points.
Ronaldo was a largely anonymous figure, although he did graze the outside of a post with one effort on goal and Milan coach Carlo Ancelotti sprang to his defence.
"Ronaldo? He did what we expected of him in the sense that he has been out for a long time and he played in bursts. He was involved in the important moments," said Ancelotti.
Ronaldo admitted he had work to do to rediscover his top form.
"It was important to win especially after a long period on the sidelines. I had some chances. For my first game, I'm happy," he said.
"I need to play and train more and gradually I'll get back to my best. It's great to be back as I really missed playing.
"I'm not far from my best. I should have scored twice today but I was lacking a bit of match sharpness."
Cagliari stunned the European Champions after just four minutes as Robert Acquafresca rose above Italy full-back Massimo Oddo to head home a corner.
Milan did little to suggest they would find a way back into the game before the break but were handed a lifeline with a soft penalty award.