Germany goalkeeper Manuel Neuer is leaving Schalke to join Bundesliga rival Bayern Munich.
Neuer, the Schalke captain, had another season on his contract but was allowed to leave immediately. Both clubs confirmed the deal on Wednesday. Bayern also announced the transfer of Brazilian defender Rafinha, a former Schalke player, from Genoa.
Bayern said Neuer would sign a five-year contract next week after returning from national team duty and passing a medical.
No details of the deal were given, but German media have widely reported that Bayern's bid was worth ?18 million ($26 million), plus an estimated ?7 million ($10 million) in bonuses linked to future Bayern successes.
''We are very pleased to have signed the No. 1 goalkeeper in Germany but also one of the top 'keepers in the world to a long-term contract,'' Bayern chairman Karl-Heinz Rummenigge said.
Neuer, 25, helped Schalke win the German Cup and reach the semifinals of the Champions League this season. If he had seen his contract through, Schalke would get no transfer fee next season, when he would have become a free agent.
''This decision was very difficult for our club because we are losing an outstanding player,'' Schalke general manager Horst Heldt said.
''Under the circumstances, this was the best decision for Schalke.''
Bayern has been courting Neuer for months and in April the goalkeeper said he would not extend his contract with Schalke.
Schalke said it was Neuer's wish to leave.
Neuer is a local product who joined Schalke in preschool days. He made his Bundesliga debut in August 2006 and played his first game for Germany less than three years later.
Neuer helped Germany finish third at last year's World Cup in South Africa.
Rafinha signed a three-year contract, Bayern said, also without giving details.
The 25-year-old Brazilian played for Schalke for five seasons before moving to Genoa one year ago.