The 31-year-old forward cost Real £56m when he joined them from the Italians in June 2009, but it is believed he has gone back to Milan on a free transfer.
The 2007 World Player of the Year has signed a two-year deal.
Appearances: 120
Cost per game: £466,666
Goals: 29
Cost per goal: £1,931,034
Games to goals ratio: 4.14
Honours: La Liga (2011-12), Copa del Rey (2010-11), Spanish Supercup (2012)
His exit comes in the wake of Gareth Bale's arrival at Real, a move which pushed Kaka further down the pecking order and meant he wanted to leave before the transfer window closed.
Talks between the player, Real president Florentino Perez and AC Milan vice-president Adriano Galliani lasted until the early hours of Monday morning.
A Milan statement said: "Last night after 20:00 CET, thanks to the traditionally good relationship between the two clubs, Real Madrid and Milan reached and formalised an agreement for the transfer of Ricardo Kaka into Rossonero colours.
"And overnight, a little before 03:00 CET in the morning, an agreement was reached with the world-class Brazilian."
After leaving Sao Paolo as a teenager in 2003, Kaka won the Champions League and a Scudetto during his six years in Milan, and landed the prestigious Ballon d'Or award in 2007.
During his time with Real he lifted the Primera Division trophy, the Copa del Rey and the Spanish Supercup.
Kaka has scored 29 goals in 87 appearances for Brazil and played at three World Cups.
Brazilian Kaka has left Real Madrid and rejoined former club AC Milan.