Borussia Dortmund captain Mats Hummels

Bayern Munich and Borussia Dortmund have agreed on Mats Hummels' transfer, both teams confirmed on Tuesday.

After a long back and forth, Borussia Dortmund captain Mats Hummels finally left to join league rivals Bayern Munich at the end of the season. The German international inked a five-year deal that will keep him at Bayern Munich until June 2021. However, both team agreed to keep silence over further contract details such as transfer fee.

The 27-year-old defender rejoins the German record champions on July 1, where he made his Bundesliga debut in May 2007 against Mainz.

"We are delighted that Mats Hummels has opted for Bayern," chairman Karl-Heinz Rummenigge said. "With his signing we increase the quality within our squad as Mats is one of the best defender in the world."

Hummels started his youth career in 1995 in Bayern before he moved to Dortmund in 2008 to make 244 top-flight appearances and score two goals ever since.

"It was not an easy decision after successful eight and a half years with Dortmund," Hummels said.

During his spell in Dortmund, Hummels reaped two Bundesliga titles, the German Cup and reached the UEFA Champions League final in 2013, where they lost 2-1 to Bayern.

Dortmund secured the second spot in the Bundesliga this season. Meanwhile, Bayern wrapped up the title for four times in a row, and the 26th in the club's history.