The defender proved a big hit with United fans when he arrived but after recovering from a serious knee injury at the start of the 2005/6 season, he found his first-team place occupied by Patrice Evra.
Liverpool tabled a bid of more than £6.8m in the belief United would be forced to sell after quoting that figure in a letter to Heinze's agent.
However, United refused to let the defender join their bitter rivals and though he considered an appeal against the Premier League's ruling, Heinze instead opted for a move to Spain.
Heinze will undergo a medical in Madrid before completing the move which will see him replace veteran Brazilian Roberto Carlos, who left the Bernabeu in the summer.