The German was in advanced negotiations with United and a breakthrough was reached when a role was offered as part of his move to the club, according to sources.
The club said in a statement that it was delighted to announce the appointment of Ralf Rangnick as interim manager until the end of the season.
"After this period, the club and Ralf have agreed that he will continue in a consulting role for two more years."
The finalisation of his British work permit is holding up his first game in charge of United, but he is expected to take charge of his first game on Thursday.
He has been the manager of several teams in the Bundesliga.
Since the dismissal of Ole Gunnar Solskjaer, United have been searching for an interim manager.
The club said that Michael Carrick will remain as interim manager until the work visa of the manager is completed. He has been in charge of the side for the last two games, first guiding them to a 2-0 win at Villarreal and then a draw with Chelsea.
"I am excited to be joining Manchester United and focused on making this a successful season for the club," he said.
The squad has a lot of talent and experience. All my efforts for the next six months will be on helping these players fulfill their potential, both individually and as a team.
I will be supporting the club's goals on a consulting basis.
According to sources, United held talks with former Barcelona manager Ernesto Valverde and also with another manager, who was previously at the club.
The club had an initial inquiry about his availability, but it was knocked back.
Sources said that Mauricio Pochettino would be interested in the Old United job but he is under contract in Paris for another five years.