Bailly made 47 appearances for Villarreal since joining the La Liga side in 2015 and the chance to work with Jose Mourinho was a major drawcard for the 22 year-old.
"It is a dream come true to be joining Manchester United. To play football at the highest level is all I have ever wanted to do, Bailly said.
"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. I am looking forward to meeting my new team-mates and to starting this new chapter of my life."
The Portuguese manager hailed the Ivory Coast international, who became his first signing since taking the reigns at United.
"Eric is a young central defender with great natural talent. He has progressed well to date and has the potential to become one of the best around, Mourinho said.
"We look forward to working with him to help nurture that raw talent and fulfil his potential. Eric is at the right club to continue his development."
Bailly has 15 caps for Ivory Coast and was part of the 2015 Africa Cup of Nations-winning team.