Madrid will host the Spanish Formula One Grand Prix from 2026 to 2035 on a new city circuit around the capital's IFEMA exhibition centre.
The announcement has left Barcelona facing an uncertain future.
The Circuit de Catalunya's current contract expires after the 2026 race but Formula One chief executive Stefano Domenicali suggested the Barcelona track could remain on the calendar beyond then.
"The fact we are in Madrid is not excluding the fact we could stay in Barcelona for the future," he said at a lavish presentation.
"Looking ahead, there are discussions in place to see if we can really extend our collaboration with Barcelona, with whom we have a very good relationship, for the future."
Sources indicated there was a possibility of Spain having two races in 2026.
The country currently has two Formula One drivers -- Carlos Sainz at Ferrari and double world champion Fernando Alonso, now 42 but still a frequent podium finisher last season, at Aston Martin.
With Sainz in the audience, Domenicali declared the Madrid contract marked the start of "an exciting new chapter for F1 in Spain.
"Spain was a market that just a couple of years ago was not in the centre of our eyes," added the Italian. "Now it is very important."
The race proposal, he said, epitomised the sport's vision of "a multi-day spectacle of sport and entertainment that delivers maximum value for fans and embraces innovation and sustainability."
Madrid last hosted a grand prix at Jarama to the north of the city in 1981, with Barcelona becoming the home of the Spanish race in 1991.
Domenicali said the Madrid deal also showed Europe was still eager to invest in the sport at a time of growth in new venues in the Americas, with the United States now hosting three races, and Middle East.
"Modern Formula One cars racing on a new circuit in the Spanish capital city of Madrid is an enticing prospect," said Mohammed Ben Sulayem, president of the governing FIA, in a statement.
"As we build towards the introduction of the FIA 2026 Formula One regulations, which have been framed with Net Zero carbon by 2030 in mind, it is pleasing to see that the local organisers have placed a sharp focus on environmental sustainability in their plans for the event."
The proposed 5.47 km circuit, using both street and non-street sections, remains subject to FIA homologation and safety checks as well as calendar approval by the World Motor Sport Council.
The layout, near the city's Barajas airport and with 90 per cent of fans expected to access the venue by public transport links, will feature 20 corners.
The venue's projected capacity is more than 110,000 spectators per day with plans to increase that to 140,000 over the first half of the agreement, making Madrid one of the largest venues on the calendar.
"This event, which we expect to be followed on a global scale by 70 million people, will represent an increase of more than 450 million euros in Madrid's GDP per year and the creation of 8,200 jobs," said the president of the Madrid region, Isabel Diaz Ayuso.