The 35-year-old Croatian international, who won the Ballon d'Or in 2018, has played 391 times for Madrid since joining from Tottenham in 2012.
"The Croatian midfielder will remain at our club until 30 June, 2022," Real said in a short statement.
Modric has remained a key player for Zinedine Zidane's men this season, scoring six goals in 48 appearances.
"Happy and proud to continue wearing the jersey of the best team in the world," he said on Twitter.
It was a very disappointing season for the 13-time European champions though, losing to Chelsea in the Champions League semi-finals and being pipped to the La Liga title by Atletico Madrid on Saturday.
Questions remain about the futures of coach Zidane and long-serving defender Sergio Ramos ahead of the 2021-22 campaign.
Standout matches today