The France international defender was suspended by Valencia for one week without pay earlier this month after publicly criticising his team-mates and coach Miroslav Djukic in a radio interview.
Rami apologised for his comments but it soon emerged the 27-year-old would not play for the Spanish outfit again and Serie A club Milan have won a race with rivals Inter Milan and Napoli for his signature.
They must, however, wait for the transfer window to open on January 1, 2014, before fielding Rami in a competitive fixture.
A statement published on Valencia's official website read: "Valencia CF and AC Milan have reached full agreement for the transfer of Adil Rami to the Rossoneri in the upcoming winter transfer market.
"Rami, until the opening of the transfer window, has received permission from Valencia CF to train with AC Milan.
"The Italian club has an option to buy the France international."
Rami's last appearance for Valencia saw him dismissed in a 3-0 Europa League defeat to Swansea on September 19 and, after he subsequently claimed on Spanish radio station Cadena Ser that "there was only confusion" in the Valencia dressing room, he was dropped from the squad.
The Corsican joined Los Che from Lille in January 2011 and made 74 appearances in all competitions, scoring five goals.