"Done deal", Milan's managing director Adriano Galliani announced on the club's website, with Milan adding that discussions ran until "between 0230 and 0300 CET in the morning (on Monday)".
According to the Italian press, Real allowed the 31-year-old to return to his former club on a free transfer, having paid 65 million euros to bring Kaka to Madrid in 2009.
The Brazilian was also said to have taken a significant pay cut to facilitate his move to the San Siro, accepting an annual salary of four million euros plus bonuses, a considerable reduction from the 10 million euros a year he received in Madrid.
"I'm very happy, the talks took a long time. I want to thank the fans and my teammates for their support," added Kaka.
Kaka's first spell at the Rossoneri, from 2003 to 2009, coincided with his rise to prominence that culminated in him winning the 2007 Ballon d'Or after leading Milan to the Champions League title that year.
Kaka, who has scored 29 goals in 87 appearances for his country, last week made a public plea to be able to leave the Spanish giants as he looks towards cementing a place in the Brazilian national side ahead of next year's World Cup.
"Kaka would strengthen us. He's versatile, and his technical attributes would be a big plus to the team," said Allegri.
"We still have two and a half days till the end of the transfer window and the club is working on it. I have faith."
Milan's push to bolster their squad before Monday's transfer deadline comes days after they qualified for the group stages of the Champions League.
