In his fifth season at Real after joining from Liverpool in 2009, Alonso posted a photo of the inside of the club's Bernabeu stadium with the caption: "This will continue to be my home for two more years. A pleasure to let you know. Very, very happy."
Alonso's current deal expires at the end of the season and the lack of an announcement of a new contract until now had prompted speculation he might accept a lucrative offer from an English Premier League club.
He has agreed a two-year extension with an option for another year and will be paid a net salary of 6 million euros a season, Spanish media reported.
Alonso's poise and passing ability have been crucial to the Madrid club's success in recent years and Carlo Ancelotti's side have looked vulnerable when he has missed games through injury.
Hugely popular with the Real fans, they made it clear they wanted him to stay by chanting his name at recent home matches.
Alonso will miss Thursday's Copa de Rey last 16, first leg at home to Osasuna as he is yet to recover fully from damage to an eardrum he sustained last month.
- Sports & Recreation