Milan edge enthralling seven-goal show
Leonardo's side, who were 2-1 down before racing into a 4-2 lead, remained third in Serie A with leaders Inter Milan and second-placed Juventus also winning over the weekend.
Clarence Seedorf gave Milan an early lead after some neat passing but the Sardinians were ahead on the half-hour after Alessandro Matri and Andrea Lazzari exposed a static defence badly missing the suspended Alessandro Nesta.
More good attacking play pulled Milan back into the match with Marco Borriello heading in and Ronaldinho then setting up Alexandre Pato to fire home late in a frantic first half.
The often inconsistent Ronaldinho, who looked refreshed following the international break, hammered in a penalty in the second half to crown another improved display but Milan's nerves were fraught in the closing stages after Nene made it 4-3.
"I've returned to work and felt good. Let's hope I can get a few more goals and we can continue like this," the Brazilian told Sky television.
Inter, who have a five-point advantage after 13 games, won 3-1 at Bologna on Saturday as they chase a fifth straight title.
Juve overcame Udinese 1-0 in a cold Turin in Sunday's late game after Fabio Grosso popped up in the area to guide in fellow fullback Martin Caceres's cross early in the second period.
The hosts, who brought on Alessandro Del Piero for only his second appearance of the campaign after injury, continued their habit of failing to find a killer second goal and were lucky that Udinese were blunted by Antonio Di Natale's suspension.
Francesco Totti had earlier marked his return from almost two months out with a recurring knee problem by scoring a powerful hat-trick in AS Roma's 3-1 home win over Bari.
The striker, who has retired from Italy duty but has hinted he would consider a return at the World Cup, netted a spot kick before blasting home a free kick and then superbly slamming in from a tight angle all inside the first half-hour.
The win was the perfect tonic for mid-table Roma, whose future ownership remains unclear amid debts and fan unrest.
Walter Zenga's Palermo drew 1-1 at home with his former club Catania in the Sicilian derby and fourth-placed Sampdoria beat Chievo 2-1 in Genoa for their first win in four games.
Napoli drew 0-0 at home with Lazio while at the bottom Siena are three adrift after a 2-0 home defeat by Atalanta which prompted supporter protests and further weakened the position of interim coach Marco Baroni.
Lowly Livorno grabbed a very late winner to beat Genoa 2-1.