European Council President Donald Tusk told David Cameron to "get real" over his "stupid referendum" before the 2016 Brexit vote, a BBC documentary reveals.
Mr Tusk tells the three-part show that he warned the then prime minister there was no "appetite for revolution in Europe" and he "could lose everything".
He claims that Mr Cameron, who did not take part in the programme, felt "there was no risk of a referendum" happening.
But Craig Oliver, Mr Cameron's former communications director, denies this.
"David Cameron spent the whole of the 2015 election campaign making clear he would not lead any form of government that didn't have a referendum," he said on Twitter.
'Amazed and shocked'
In BBC Two's "Inside Europe: Ten Years of Turmoil", which starts next Monday, Mr Tusk said Mr Cameron thought a referendum would not happen because of the coalition government with the Lib Dems.
"[He told me] he felt really safe, because he thought at the same time that there's no risk of a referendum, because his coalition partner, the Liberals, would block this idea of a referendum," Mr Tusk said.
"But then, surprisingly, he won and there was no coalition partner. So paradoxically David Cameron became the real victim of his own victory."
Mr Tusk said he was "really amazed and even shocked" to learn from Mr Cameron that he decided to hold the referendum because of his own party.
Mr Cameron decided to resign as prime minister when the Leave campaign won the referendum.
The programme's producers said he did not take part in the programme because he has signed an exclusive deal for his memoirs.
Mr Tusk warned Mr Cameron that other European prime ministers would not be inclined to help him in the referendum, and says: "For the first time I saw something close to fear in his eyes. He finally realised what a challenge he was facing."
And after hearing Mr Cameron's decision to quit, Mr Tusk says he told him: "Yes David, it would be very difficult even to imagine that a prime minister who was the leader of Remain's campaign would be just two days later a prime minister negotiating Brexit.
"It was like his day of reckoning was coming, reckoning for his biggest mistake in his life."
The first episode of the three-part series features interviews with former chancellor George Osborne, ex-foreign secretary William Hague, European Commission President Jean-Claude Juncker and former French presidents Nicolas Sarkozy and Francois Hollande.
Nick Clegg, the UK's then EU ambassador Sir Ivan Rogers and Mr Oliver are also included.
In the programme, Mr Sarkozy reveals how he warned Mr Cameron about his attempt at strong-arm tactics with EU leaders over concessions on migrant rules and integration, telling him: "If you try to break our arm, you'll get nothing."
And Mr Hollande says that during a visit to Chequers in 2015 he tried to talk the Tory leader out of holding the referendum.
"Nothing obliged him to hold the referendum when he did," he tells the documentary.
"This would not be the first time that a commitment made at an election had not been kept afterwards, but he wanted to show he could negotiate successfully with Europeans."
Theresa May, who is criticised in the programme by Mr Osborne - who she sacked as chancellor, also declined to take part in the programme
Describing a meeting held by Mr Cameron to get ministers' views on whether to back a referendum, Mr Osborne said: "Theresa May didn't say very much, which was par for the course in those meetings."