A conservative was sworn in on Saturday as Madrid's new mayor, regaining control of the Spanish capital for the People's Party after forging a coalition including the far right, while the far-left won a second term in Barcelona with support from the Socialists and others.
Spain's municipal elections in May led to a fragmented political landscape, requiring numerous power-sharing deals to form coalition governments, with the most vote-winning candidates kept out of office in some places.
The PP's candidate for Madrid mayor, Jose Luis Martinez-Almeida, came second behind a far-left candidate but he won control of the city government with the backing of the far-right Vox as well as the centre-right Ciudadanos party.
Some members of Ciudadanos have expressed unease over the party's decision to deepen its alliance with Vox and the PP to secure a share of power in Madrid and the southeastern Murcia region.
In neighbouring France, President Emmanuel Macron's government warned Ciudadanos, its Spanish centre-right ally in the European Parliament, of possible "consequences" if it went ahead with local alliances with Vox.
Under the municipal electoral system in Spain, city halls must choose a mayor from whichever group forms a majority if no single candidate wins outright.
The Socialists won the most support in May's elections, with 29.3% of the vote, followed by the PP on 22.2%.
In Barcelona, far-leftist mayor Ada Colau also came second in the elections but she was re-elected with support from the Socialists and a platform backed by former French prime minister Manuel Valls in a deal aimed at preventing a Catalan pro-independence leader from taking the job.
"I will not be a secessionist or anti-secessionist mayor," Colau said after being sworn in, adding that she felt somewhat uncomfortable over the way she was re-elected. She was at odds with Valls during the campaign in Spain's second-largest city.
Hundreds of people demonstrated outside Barcelona's city hall, some in favour of Colau and others for pro-independence groups. One elected city council member, Joaquin Forn, is among the jailed Catalan leaders on trial at Spain's Supreme Court for their role in the region's failed independence bid in 2017.
He received permission from the court to be transferred from a jail in Madrid to attend Barcelona's municipality inauguration, only to be sent back to Madrid immediately after.