Spain’s parliament has chosen Socialist leader Pedro Sánchez to form a new government and head a leftist coalition government. Sánchez won by 167 votes against 165, with 18 abstentions.

Sánchez has been caretaker prime minister since early last year. His narrow margin of victory has raised doubts about how long the coalition government will last, as its policies require parliamentary approval.

Sánchez’s Socialists won two consecutive general elections last year, but both times they failed to capture a parliamentary majority. That meant they couldn’t win the parliamentary confidence vote that is required before taking office.

The country has been run by Sánchez’s caretaker government for close to a year, and today’s ballot of lawmakers is his latest attempt to take office.