The 25-year-old, who will miss Euro 2016 and the start of the new Premier League season through injury, becomes the first signing for incoming City manager Pep Guardiola.
City have reportedly paid a fee of about £20m for Gundogan.
"When I learned of City's interest, my heart was set on coming," he said. "Things have moved very quickly."
The Premier League club's director of football Txiki Begiristain praised Gundogan's "work ethic and technical ability".
"He is an intelligent and versatile midfielder who can operate in a number of different roles," Begiristain added. "He will be a very important player for us in the coming years."
Gundogan dislocated his kneecap in training at the start of May and was also sidelined for the 2014 World Cup with a back problem that ruled him out for almost the entire 2013-14 season.
"The opportunity to work with a coach like Pep Guardiola is something I am really looking forward to and I am flattered to be the first signing the club has made this summer," he added.
"I will give everything to help us win titles both in England and the Champions League. These are exciting times. I have my best years ahead of me and I think we can achieve great things together."
The midfielder joined Dortmund from Nuremberg in 2011 and helped them reach the 2013 Champions League final, before signing a new contract in 2015 that still had a year to run.
Manchester City have signed Germany midfielder Ilkay Gundogan from Borussia Dortmund on a four-year deal.