Fines for vehicles entering areas of central Madrid have been reinstated, five days after a low emission zone policy was suspended.
The new conservative mayor, José Luis Martínez-Almeida, had shelved the initiative known as Madrid Central.
It was introduced by his left-wing predecessor, Manuela Carmena, in November to meet EU rules on clean air.
A court reinstated the ban after a spike in pollution and mass environmental protests.
The People's Party-run city hall, which came into power on 15 June, had suspended the ban on most petrol and diesel cars entering the centre.
It had been introduced to ramp up anti-pollution efforts and mirrored schemes in other European cities like London, Stockholm and Milan, whose governments wanted to tackle the harmful effects of vehicle emissions.
Since Madrid Central came into force seven months ago, the lowest air pollution was recorded in 10 years.
But in the five days since the ban was lifted, there had been a "surge" in pollution, environmental groups say.
On Monday, thousands of protesters hit the streets to protest against Mr Martínez-Almeida's decision to shelve the policy.
The Spanish Socialist Workers' Party, along with a group of various environmental organisations, presented an appeal against the lifting of the ban.
The judge said "the health of Madrid" was more important than "the right to travel by car" and reversed the decision.
It will mean that most vehicles once again cannot enter the low emissions zone in central Madrid.