Milan have been linked with a move for Spanish winger Castillejo throughout the transfer window and announced his arrival via their official website.
Castillejo joined Villarreal from Malaga ahead of the 2015-16 season and the 23-year-old has made 91 LaLiga appearances and scored nine goals for the club.
It has been a busy transfer window for the Rossoneri, who also signed versatile left-sider Diego Laxalt on Friday.
The duo join the likes of Gonzalo Higuain, Mattia Caldara and Tiemoue Bakayoko in moving to San Siro during the transfer window, but Milan have moved to rule out an audacious swoop for Lazio's much sought after midfielder Sergej Milinkovic-Savic on an initial €40million loan ahead of a permanent switch.
Meanwhile, Bacca has left Milan permanently for Villarreal on a four-year deal.
The Colombia striker spent the 2017-18 campaign on loan with the club, scoring 15 goals in 35 LaLiga appearances.
Bacca moved to Milan amid much fanfare prior to the 2015-16 campaign and netted 31 times in Serie A for Milan.