US President Donald Trump said Spanish Prime Minister Pedro Sanchez deserved to lose the parliamentary election, welcoming the result after a reporter told him Sanchez had been defeated.

Asked whether he was pleased with the outcome, Trump first said: “Well, Spain is not doing too well right now. What was the final result?” After the reporter replied that Sanchez had lost, Trump said: “He lost? Oh, that’s a good thing. He did a terrible job. He deserves to lose.”

A few seconds later, Trump added with surprise: “Wait a minute, Sanchez lost, huh? Oh, that’s great news.”

The right-wing bloc won Sunday’s parliamentary election in Spain, which is preparing to end eight years of socialist rule. Sanchez, a critic of Trump, conceded defeat.

Sanchez’s refusal to meet US demands for Spain to raise defence spending to 5% of GDP irritated Trump. Spain also closed its airspace to US aircraft involved in attacks on Iran.

Sanchez has drawn global attention for taking firm positions on progressive issues, from recognising Palestinian statehood to defending multilateral institutions and taking tough action against “tech oligarchs”. His responses to the Trump administration’s actions reflected a longstanding ideological position on the Spanish left.

The Spanish left has long had an ambiguous relationship with the United States and shown significant opposition to joining NATO, according to The New York Times.