The Serie A club announced the French defender had moved to the San Siro on a three-year contract.
The 28-year-old spent the second half of last season on loan with the Rossoneri after falling out of favour at Spanish side Valencia.
Milan had an option to make the deal permanent this summer, but were unwilling to pay the asking price set by Los Che.
But, after weeks of negotiation, the clubs reached an agreement for Rami to move to Milan for a reported fee of 4.25million euros (£3.375million).
Rami scored three goals in 18 league appearances for Milan last season.