BERLIN  - Spain midfielder Javi Martinez signed for Bayern Munich on Wednesday, the club confirmed, in a deal believed to be a new Bundesliga record transfer of around 40 million euros (US$50.2m).

The 23-year-old has been a Bayern target for weeks and terminated his contract with Athletic Bilbao on Wednesday, which allowed him to sign a five-year deal with Bayern until June 2017. The player had a release clause with Athletic to the tune of 40 million euros, but he was responsible for paying it himself, adding huge tax liabilities as a result.

"Without question, that was a complicated transfer," admitted Bayern chairman Karl-Heinz Rummenigge with the transfer window set to close on Friday. "So we are very happy that Javi Martinez is finally with us. "We know he is a very good player, with a strong personality and he has an affinity for Bayern Munich, which he has clearly demonstrated in the last few days.

"Along with our coach Jupp Heynckes and director of sport Matthias Sammer, we are looking forward to working with Javi Martinez." The club did not confirm the final price of the transfer, but German media report the deal is expected to be a new league record.

It should better the 34 million euros ($42.6m) Premier League side Manchester City paid VfL Wolfsburg for Edin Dzeko in 2011 and the 30 million euros ($37.6m) Bayern paid VfB Stuttgart for Mario Gomez in 2009.

The transfer saga was played out on Wednesday after German Sky TV broadcast images of Martinez arriving in Munich at midnight on Tuesday before he completed the medical in the early hours.

He was then reported to have flown back to Spain and Athletic issued a statement on Wednesday demanding an explanation and insisting they had not authorised his trip to Germany.

Bayern said Martinez will hold a press conference on Thursday in Munich.

The defensive midfielder, who has also been used by his club at centre-back, has made eight appearances for Spain and came off the bench for Spain briefly at both the 2010 World Cup and Euro 2012.

Bayern have already strengthened their squad this season with midfielder Xherdan Shaqiri arriving from FC Basel, striker Mario Mandzukic from Wolfsburg and Brazilian defender Dante from Borussia Moenchengladbach.