MADRID, Oct 29 (Reuters) - Spain ended 10 months of political gridlock on Saturday when lawmakers agreed to grant conservative leader Mariano Rajoy a second term as prime minister.

After two inconclusive elections and fruitless attempts at coalition-building between bickering parties, Rajoy will now form the first fully-functioning government since December, albeit with the weakest mandate in Spain’s modern history.

Without a majority in Spain’s fragmented parliament, Rajoy’s administration will have to negotiate pacts with opponents if it wants to see out its four-year term and pass laws, starting with a new budget plan for next year.

“We’ve survived more than 300 days with an acting government but we will not survive a government that cannot govern because it lacks support or faces too many obstacles,” Rajoy told lawmakers, urging them to safeguard Spain’s economic recovery. “I’m not asking for the moon.”

Rajoy’s rivals have so far not guaranteed him any form of political stability, though the threat of another snap election, which his People’s Party (PP) would likely win once again, may afford him some reprieve.

After governing as caretaker prime minister since December, Rajoy won a parliamentary confidence vote on Saturday after dozens of lawmakers from his long-standing Socialist opponents lifted their veto on his second term and abstained.

He said he would name a new cabinet on Thursday.

The confidence vote marked a personal triumph for 61-year-old Rajoy and confirmed his reputation as a political survivor.

After winning an election in 2011, he imposed deep spending cuts to tackle a soaring deficit as Spain endured a deep recession and unemployment rocketed to nearly 27 percent. Rajoy’s PP was also tainted by a series of corruption scandals.

Voters punished the party even as the economy later recovered, stripping it of its absolute majority. But it still won the most votes in elections last December and in June, and Rajoy resisted calls from rival parties to step aside.

STRUGGLE WITH THE OPPOSITION

Rajoy struck a conciliatory tone this week, offering to work with opponents on issues like pension and education reform, and opening the door to further dialog with Catalonia, a northeastern region in the grip of a strong independence drive.

But many in Spain are skeptical of what the government can achieve, with just 137 seats in the 350-strong parliament.

“There’s no consensus to reach any broad agreement between everyone and I can see this situation getting worse,” said Begona Herrero, 65, a property agent in Madrid.

Rajoy, who may need to pass fresh spending cuts to meet deficit targets set by Brussels next year, will be able to count on support on some issues from the liberal Ciudadanos or “Citizens” party, which came fourth in June elections.

But others - including the second-placed Socialists and anti-austerity Podemos (”We Can”), the third-biggest party in parliament - have said they will fight Rajoy’s policies and will not approve his budgets.

Several thousand people marched in protest against a new Rajoy government in the capital on Saturday.

“Rajoy is going to keep making cuts to education, healthcare and eroding workers’ rights like he did when he was last in power,” said Angel Guillen, 40, who works in the Madrid local government.

A DIVIDED LEFT

Rajoy will attempt to outmaneuver a divided and distracted left-wing.

The Socialists, in power for half of the past four decades, were torn apart over their leaders’ decision to allow Rajoy to govern. They now face a challenge from Podemos to lead the opposition.

Former Socialist leader Pedro Sanchez, ousted in early October over his refusal to enable aRajoy government, quit his seat in parliament rather than abstain in the confidence vote, and 15 other Socialist lawmakers broke with the party line and opposed Rajoy’s re-election.

Sanchez suggested he could try and run for the party leadership again in upcoming primaries.

“I completely disagree with the decision to enable Mariano Rajoy to govern,” a tearful Sanchez told a news conference earlier on Saturday.

“From Monday onwards I’m going to get into my car and go all over Spain to listen to those that are not being listened to.” ($1 = 0.9142 euros) (Additional reporting and writing by Adrian Croft, Maria Vega Paul and Angus Berwick, Editing by Mark Bendeich and Richard Balmforth)