Bailly, who has 15 caps for Ivory Coast, made 47 appearances for Villarreal after joining in 2015.
The 22-year-old becomes the first signing for manager Jose Mourinho at Old Trafford.
"I want to progress to be the best that I can be and I believe working with Jose Mourinho will help me develop in the right way and at the right club," Bailly said.
"I am looking forward to meeting my new team-mates and to starting this new chapter of my life."
Image: Villarreal's Eric Bailly celebrates after scoring against Dinamo Minsk during the Europa league Group E match at the Madrigal stadium in Villarreal, Spain, October 22, 2015.
Photograph: Heino Kalis/File Photo/Reuters
Mourinho's dwindling options bode well for Man United
Manchester United: The Three Key Mistakes...
Always a pragmatic manager... now a champion!
Manchester United and South American players: Not quite a perfect mix
Ibrahimovic will sign for Manchester United - Sky sources