Kaka initially left Milan for Real in 2009, but the Brazilian has struggled to display his best form at the Bernabeu.
The 30-year-old had suggested he would be keen to return to the San Siro and Milan were hoping to bring back Kaka on loan.
But Galliani says any deal is now off after Milan were unable to reach an agreement with Real over a temporary arrangement.
"The negotiation has failed," Galliani told the Italian media. "We have given up due to the fiscal situation.
"Kaka made every possible effort but everything has failed due to the fiscal situation that convinced Real to stop the negotiations.
"At this point, I think we will remain as we are."
Reports in Italy claim Milan wanted to sign Kaka on loan until the summer of 2015 when his Real contract ends, but that the Spanish champions were only interested in a permanent deal.