Tuesday’s vote ends almost a year of political limbo for the eurozone’s fourth-largest economy.
Sánchez won a cliff-hanger confidence vote by 167 votes against 165, with 18 abstentions.
The confidence vote was already forecast to be extremely close, but Socialist leader Pedro Sánchez’s administration was widely expected to be elected by this exact difference.
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.