Carlo Ancelotti has agreed a contract in principle with Bayern Munich to replace Pep Guardiola at the end of the season, the Guardian understands. The German club hope to announce that he is joining the club in the next few days, after Guardiola has made public his decision to leave.

The Bayern hierarchy has known for some time now that Guardiola does not want to renew his contract after three years in Bavaria and they moved swiftly to approach the former Milan, Chelsea, Paris Saint-Germain and Real Madrid manager. Ancelotti has been on a sabbatical since leaving the Spanish club in the summer, taking time out to recharge his batteries after two successful seasons in Madrid.

Ancelotti’s representative and Bayern have been discussing the finer details of the contract, which is for three years, over the past few days but there is nothing to suggest that it will not be finalised.

Bayern play Hannover on Saturday afternoon and are expected to announce on Sunday that Guardiola is leaving although the Spaniard may well make the announcement himself after the game.

Bayern hope the news that Ancelotti, who has won the Champions League three times, has agreed to take over will soften the blow of losing Guardiola.

The Spaniard has won the league in both his seasons at Bayern – and the cup in this first year – and is on course to win his third successive title this year, with the team also in the last 16 of the Champions League, where they face Juventus.

The Bundesliga club are confident that the news that Guardiola is leaving will not have an impact on the players, with Thomas Müller, Xabi Alonso, Jérôme Boateng and Javi Martínez all signing new contracts on Friday.

It is only three seasons ago that they were faced with a similar scenario as the news that Guardiola would take over from Jupp Heynckes broke in January 2013. That season they went on to win the treble, claiming the Champions League, the Bundesliga and the German Cup.

Guardiola will not be short of offers for next season with Manchester City, Chelsea and possibly Manchester United looking for a new manager.