The 23-year-old Uruguay international's original agreement ran until 2025 but he signed a deal for a further two years, and it reportedly includes a €1billion release clause.
A statement on Madrid's website on Tuesday said: "Federico Valverde signed a contract renewal at Real Madrid. The Uruguayan midfielder remains linked to our club until June 30, 2027."
Valverde joined Madrid from Uruguayan club Penarol in July 2016, initially playing for Real Madrid Castilla, the club's reserve team.
He joined Deportivo La Coruna on loan for the 2017-18 season before establishing himself in the Madrid first-team setup under Santi Solari.
Valverde won LaLiga in 2019-20 under Zinedine Zidane, making 21 starts. Last season he featured 24 times for Madrid in the league and scored three goals.
The midfielder becomes the latest player to agree new terms at Madrid since Carlo Ancelotti took charge of Los Blancos in June.
Luka Modric, Nacho Fernandez, Karim Benzema, Dani Carvajal and Thibaut Courtois have all recently signed new deals.