David Cameron took Britain closer to the exit door of the European Union last night following a tumultuous EU summit at which his fellow leaders inflicted a crushing defeat on the prime minister by nominating Jean-Claude Juncker for one of the most powerful jobs in Brussels.

In what marked a rift in the UK's long and troubled relationship with the continent, Cameron was left isolated as 26 of 28 countries endorsed Juncker as head of the European commission for the next five years. "This is a bad day for Europe," said the prime minister as he voiced bitterness over the nomination of Juncker. "Of course I'm disappointed." He described the nominee disparagingly as "the career insider of Brussels" and criticised other EU national leaders who he said had "taken different views along the way".

Accusing the leaders of Germany, France, Italy and another 23 countries of making "a serious mistake" by abandoning an approach that could have brought consensus on an alternative to the former prime minister of Luxembourg, Cameron said: "We must accept the result … Jean-Claude Juncker is going to run the commission."

Cameron admitted that he now faced an uphill struggle to keep Britain in the EU if his mooted in/out referendum on membership goes ahead as scheduled in 2017. "Today's outcome is not the one I wanted and, frankly, it makes it harder and it makes the stakes higher," he said.

"This is going to be a long, tough fight. Frankly you have to be willing to lose a battle in order to win a war … Europe has taken one step backwards with its choice of commission president."

Pierre-François Lovens, a journalist with La Libre Belgique, tweeted a selfie of himself with Juncker in what appeared to be a bar where he was apparently awaiting the result of the vote. Lovens tweeted: "The man waits, serene, calm, smiling."

Juncker tweeted after the vote that he was delighted to have been nominated. "I am proud and honoured to have today received the backing of the European council." In a second post he tweeted: "I am now looking forward to working with MEPs to secure a majority in the European parliament ahead of the vote on 16 July."

On a momentous day in Brussels which shifted the balance of power in Europe, the decision to back Juncker also handed a big victory to the European Parliament over the way the EU is run.

No vote has ever been taken among national leaders on who should head the commission, a decision that until now has always been taken by consensus. But given Cameron's immovable opposition to Juncker, the issue was put to a qualified majority vote, with Cameron supported solely by Viktor Orbán, the pugnacious Hungarian prime minister.

Other allies who had previously voiced sympathy with the British line of argument – the Swedish and Dutch prime ministers – have peeled away to side with the majority over the past week, leaving Cameron unusually isolated.

But the big shift was that no other candidates but Juncker were considered for the powerful EU executive post because the European Parliament set the leaders by insisting on Juncker after his Christian Democrats grouping won last month's European elections.The German chancellor, Angela Merkel, a Christian democrat, was the key supporter of Juncker, despite Cameron's earlier confidence that Berlin shared his reservations about the 59-year-old, who ended a 19-year stretch as prime minister of Luxembourg last year.

Bowing to the European parliament's insistence on Juncker marked a seismic shift in the way the EU is run, with the national elected leaders ceding power to the parliament on the question for the first time. There were signs that the government chiefs realised they had blundered, but the momentum behind Juncker had become irreversible. While nominating him, they also decided to review the nomination process, suggesting they would try to claw back their prerogatives from the parliament.

Cameron made clear that he would stop short of embarking on the step that some eurosceptics and even some ministers have been urging him to take- campaigning for a No vote in his planned referendum unless the EU embarks on significant reform.Asked whether the appointment of Juncker made it more likely that he might campaign for a referendum no vote, the prime minister said: "My goal is exactly the same as it was before today, which is to act in Britain's national interest. I believe Britain's national interest lies in reforming the EU, holding a referendum about that reform in the EU and recommending that we stay in a reformed EU. Has that got harder to achieve? Yes. Is it still the right thing to do? Yes. Will I give it absolutely everything I have got to achieve it. Yes I will. "

"Clearly the job has got harder. I wouldn't deny that for one second."

Ukip's leader, Nigel Farage, said the appointment showed Cameron was a "loser". He tweeted: "David Cameron's response to Juncker's appointment shows that he is a loser who has learned nothing."

A leading Tory Eurosceptic said that the prime minister's defeat had shot to pieces his strategy of renegotiating Britain's membership terms with other EU leaders before a referendum. Daniel Hannan, a Tory MEP who wants to leave the EU, wrote on his Daily Telegraph blog: "The game is up … If David Cameron couldn't prevent the appointment of Jean-Claude Juncker as president of the European commission, no one will believe that he can deliver a more flexible EU, with more freedom of action for its member nations."

The prime minister will face Tory MPs when he makes a statement to parliament on Monday on the summit. But there are signs that hardline Tory Eurosceptics will hold their fire to help the prime minister deliver his referendum.

Ed Miliband, who will reply to the prime minister's Commons statement, tweeted: "On Europe, David Cameron has now become a toxic prime minister … He cannot stand up for Britain's national interest because when he supports something he drives our allies away."

On another of Cameron's key demands, the scrapping of the EU's commitment to "ever closer union" in the preamble to the Lisbon Treaty, the prime minister admitted this would be a tough fight. The summit declared the EU's adherence to ever closer union, though conceding that this could include varying levels and rates of integration, a statement of the status quo that Cameron sought to portray as a shift.

Merkel made it plain she had little intention of dropping the contested commitment to "ever closer union".

"There can be different speeds for member countries to adopt come to ever closer union," she said. "It was made clear, yet again, that the idea of an ever closer union as it is stated in the treaties does not mean that there is equal speed among member countries."

She signalled frustration with what she clearly saw as Britain's over-reaction to the Juncker issue.Merkel said she hoped Britain would not consider leaving the EU following the Juncker nomination. "I think, quite frankly, that one should look at it in a much more sober way," she said. "I have a great interest in Great Britain staying a member of the European Union. In this spirit I will continue to work."

Sounding at times emotional, the prime minister maintained that his European strategy remained on course, despite the thorough defeat. In remarks that appeared contemptuous of EU politicking, he repeatedly criticised the "cosy" consensus culture and complained about having to return for another summit in under three weeks. "Another day in paradise," he said.But Downing Street set great store by the summit's agreement to consider British concerns as it wrestles with its European destiny. The prime minister wants to embrace an idea proposed by the Dutch prime minister Mark Rutte which calls for a declaration that the EU should act where necessary and national governments should act wherever possible.

"We have broken new ground because for the first time all my 27 fellow heads of government have agreed explicitly that they need to address Britain's concerns about the EU," said Cameron.

The prime minister robustly defended his decision to pursue his opposition to Juncker in the most strident terms despite the certain knowledge that he confronted a sweeping majority against him.

"This is an important stand but it is far from being the last stand."