BARCELONA, June 17 (Reuters) - Spain's Socialist Prime Minister Pedro Sanchez was given a last-minute consolation on Saturday when Barcelona's city council appointed a new Socialist mayor after a deal involving two rival parties.
Despite pro-independence parties appearing certain to run Spain's second city, Jaume Collboni, the Socialist candidate, became mayor after the far-left Barcelona en Comu of the outgoing mayor Ada Colau gave him its support in a move supported by the conservative People's Party.
The decision was a boost for the Socialist Party, which leads the national government, after mostly poor results in local elections around the country on May 28.
The local results, along with a widespread loss of power in regions which were holding elections the same day, prompted Sanchez to bring forward to July 23 a national vote scheduled to take place by December.
Xavier Trias, 76, who represents the pro-business, pro independence party Junts per Catalunya, had been favourite to become mayor until the 11th-hour deal favouring Collboni.
"The decision has been made to avoid a Junts government that extends red carpets to lobbies and sectors favourable to right-wing policies," Barcelona en Comu said in a statement.
Collboni replaces Colau, who in her eight-year tenure had restricted the opening of new hotels in a bid to curb mass tourism and set strong targets for social housing.
The political shift in Barcelona is a further setback for Catalonia's pro-independence movement, which has faltered in recent years.