Measures that ban all non-essential trips in and out of the capital and nine of its suburbs — covering around 4.8 million people — are set to be enacted on Friday evening.
Spain’s Socialist prime minister, Pedro Sanchez, said there was a “critical” need to take the new steps in the European coronavirus hot spot.
But officials in the capital, whose regional government is managed by the conservative Popular Party, baulked at the order, saying it would bring chaos and further sap the economy.
It has filed an appeal at the National Court against the new measures.
Under the national order, travellers will need to prove they are going to or from work, to see a doctor or to conduct essential administrative or legal errands in order to leave Madrid or the town where they live.
Restaurants must close at 11pm and shops at 10pm, with a restriction of 50% capacity.
Similar measures already apply to more than a million residents, and the region has limited social gatherings to a maximum of six people.
Madrid’s legal challenge argues that restrictions violate regional self-rule laws.
The city is leading the resurgence of the virus in Spain, which has Europe’s highest cumulative caseload — 770,000 since the onset of the pandemic.
The capital had a two-week infection rate of 695 cases per 100,000 residents on Thursday, more than twice the national average of 274 and seven times the European average, which stood at 94 per 100,000 residents last week, according to the European Centre for Disease Control and Prevention.
But Madrid regional health chief Enrique Ruiz Escudero said the situation is improving, with the infection rate falling to 607 per 100,000 on Friday and four consecutive days of fewer people being admitted to hospital.
“The numbers give us reason for hope,” he told a news conference.
Madrid legal chief Enrique Lopez said authorities will comply with the order, deploying more police, even though they believe it will “create chaos”.
He estimated the order will cost the Madrid economy 8 billion euros (£7.2 billion).
Mr Sanchez has refused to budge, saying Madrid faces “a moment of extraordinary seriousness”.
“The situation in Madrid is critical because (the region) has 33% of (Covid-19) deaths,” he said in Brussels, where he was attending a European Union summit.
Some passengers at Madrid’s main train station, Atocha, welcomed the new steps.
“I think they need to take strong measures to control the epidemic here in Madrid,” said Vicente Mira, a 62-year-old retired teacher.
Communication manager Pablo Torres, 36, wanted officials to get tough, saying the current measures are “nonsense and a sticking plaster on something that is a lot bigger problem”.
It was not immediately clear how the new measures might affect the few tourists arriving in Madrid, but regional authorities cannot ban foreign visitors unless Spain closes its borders.