Borussia Dortmund have reached an agreement to re-sign midfielder Mario Gotze from Bayern Munich.
Dortmund announced on their official website that Gotze, who made his controversial switch to Bayern in 2013, has agreed a contract until 2020 and will complete the transfer subject to passing a medical.
No details of the fee were released but German publication kicker said he will cost an initial €26 million plus performance-related bonuses.
The 24-year-old Germany international, whose Bayern contract is due to expire at the end of the season, struggled to live up to expectations at the Allianz Arena and was not part of new coach Carlo Ancelotti's plans.
- Borussia Dortmund (@BVB) July 21, 2016
Gotze had been linked with a return to Dortmund for some time, despite opposition from some supporters still unhappy over his exit, and it was confirmed in recent days that talks were underway.
Dortmund CEO Hans-Joachim Watzke told the club's official website: "I am very happy that Mario has opted for Borussia Dortmund. Ever since his departure in 2013, I hoped he'd return one day.
"I would like to thank Bayern Munich CEO Karl-Heinz Rummenigge in particular. We've agreed three transfers with Bayern this transfer period. All of our talks were shaped by the greatest respect and mutual trust.
"Mario is a Dortmund lad, he's one of the best creative midfielders in Europe and only 24. He had several options and consciously opted to return to his hometown club, a path which will certainly not be easy."
Gotze, who was born in Bavaria but grew up in Dortmund and joined the BVB youth academy as an eight-year-old, added: "When I left BVB for FC Bayern in 2013, it was a conscious decision and one I don't want to hide today.
"Three years on, and now 24, I look at it from a different view. I can understand that many fans were not able to relate to my decision. I wouldn't repeat it from where I am today.
"When I now return to my home, I want to try to convince all people with my performances, especially those who will not welcome me with open arms. It's my goal to play my best football again. For us all, the club and the BVB fans."
Gotze had been tipped for a reunion with former BVB boss Jurgen Klopp at Liverpool earlier in the summer but he then announced ahead of Euro 2016 that he wanted to fight for his place at Bayern.
Bayern CEO Rummenigge reacted to Gotze's declaration by making clear that he would not secure regular game time this season and should reconsider his plans.
Speaking after his return to Dortmund was confirmed, Rummenigge told Bayern's official website: "The negotiations were very fair and serious.
"We'd like to thank Borussia Dortmund, Mario, his father as well as his agent for that. I think the transfer is a good solution for all parties. FC Bayern thanks Mario Gotze for three years wearing the Bayern shirt and wishes him all the best for the future."
OFFICIAL | @MarioGoetze has completed a move to Borussia Dortmund.
All the best, Mario! pic.twitter.com/YTGlXamROR
- FC Bayern English (@FCBayernEN) July 21, 2016
Gotze becomes the second player to join Dortmund from Bayern this summer after 25-year-old midfielder Sebastian Rode signed a four-year deal at the Westfalenstadion in early June.
Germany international Mats Hummels, 27, moved in the opposite direction in May, leaving Dortmund after eight-and-a-half years to return to his first club.