David Cameron feared he would be ousted as Tory leader if he did not commit to holding a referendum on Britain's membership of the EU, his former communications chief has said.

Sir Craig Oliver said Mr Cameron would have been hit by a wave of Conservative defections to Ukip if he had not promised to give the country the opportunity of an in/out vote.

In an interview for the BBC Radio 4 series The Cameron Years, Sir Craig said Eurosceptic backbenchers had been “lining up” to become “kamikaze pilots” and bring him down.

Following months of speculation, the then prime minister announced in January 2013 that there would be a referendum if the Conservatives were returned to power in the general election in 2015.

Sir Craig said Mr Cameron and those around him took the decision in part because the issue had become a “massive boulder in the road” for the Government, standing in the way of everything they wanted to do.

“The second reason I think that they wanted to do it was that knowledge that actually they would probably have to go as leadership of the party if they didn't do it,” he said.

“Now you could say, actually you could take a principled decision and say I'm not doing it. It's not the right thing for the country or the party.

“But their view was, if they gave up, then somebody would be elected who would - and probably not do it in the way that they thought was best for the party in the country.”

In the event two Conservative MPs, Douglas Carswell and Mark Reckless, did defect to Ukip, but Sir Craig said there could have been many more.

“There was absolutely no doubt that there were people who were lining up to do it and be kamikaze pilots to make sure that this thing happened,” he said.

“There weren't specific numbers but I think that there was a sense that you could end up with, you know, another six to 10 that were just going.”

Mr Cameron's policy chief Sir Oliver Letwin described how, after the Conservatives were re-elected, he was asked by the prime minister to try to persuade Boris Johnson to back Remain.

“It was more than one phone call, it was a large number of meetings,” he told the programme.

“It was part of a continuing conversation. And we didn't quite get there.”

Sir Oliver said he believed the result “might well have gone the other way” if Mr Johnson had not decided to put himself at the head of the Leave campaign.

David Cameron's premiership - in pictures Show all 15 1 /15 David Cameron's premiership - in pictures David Cameron's premiership - in pictures Britain's Queen Elizabeth II greeting David Cameron at Buckingham Palace for an audience to invite him to be the next Prime Minister on 11 May 2010 PA David Cameron's premiership - in pictures Prime Minister David Cameron and his wife Samantha wave from the steps of Number 10 Downing Street on 11 May 2010 Getty Images David Cameron's premiership - in pictures On 12 May 2010 Prime Minister David Cameron said in a press conference with Lib Dem leader Nick Clegg, who was then deputy PM, they plan to "take Britain in a historic new direction" and Conservative-led coalition government would be united and provide "strong and stable" leadership Rex David Cameron's premiership - in pictures A decade ago, David Cameron visited the Arctic to witness the effects of climate change. However since coming to power in 2010, his government has gradually dropped down a succession of green policies David Cameron's premiership - in pictures Prime Minister David cameron told the then New York mayor Michael Bloomberg, the Queen had “purred down the line” after he told her Scotland had voted against independence in September 2014. He was forced to apologise for breaking constitutional convention Getty Images David Cameron's premiership - in pictures Britain's Prime Minister David Cameron greeted soldiers working on flood relief in York city centre after the river Ouse burst its banks, in northern England in December 2015 REUTERS David Cameron's premiership - in pictures Claims that David Cameron performed an obscene act with a dead pig and smoked cannabis during his studies at Oxford University spread around the world in September 2015. The extraordinary allegations were made in an unauthorised biography of the Prime Minister written by Lord Ashcroft David Hartley/REX Shutterstock David Cameron's premiership - in pictures In 2016, Mr Cameron was caught up in a worldwide scandal dubbed the “Panama papers” Reuters David Cameron's premiership - in pictures Prime minister David Cameron and his wife Samantha with seven week old Regan as they meet her parents, first time home buyers Robert Arron and Kelly Jeffers at the Heritage Brook housing development in Chorley, Lancashire. David Cameron has joked that he wants "another baby" and said that he feels a "bit broody" every time he sees a newborn on the campaign trail David Cameron's premiership - in pictures Prime Minister David Cameron was criticised for branding refugees in the Calais ‘jungle’ camp as a “bunch of migrants” in January 2016 after thousands of refugees died in their attempt to cross the Mediterranean in 2015 Sky News David Cameron's premiership - in pictures Britain's Prime Minister David Cameron speaks with European Commission President Jean-Claude Juncker during an EU summit meeting on 17 March 2016 at the European Union council in Brussels. Cameron was in Brussels to renegotiate deal of UK membership with other European leaders. The deal, sealed after hours of haggling at a marathon summit, paved the way for a referendum on whether Britain will stay in the EU AFP/Getty Images David Cameron's premiership - in pictures President Barack Obama shakes hands with British Prime Minister David Cameron at a meeting at 10 Downing Street in London on 22 April 2016. The President and his wife visited 10 Downing Street where he joined press conference with British Prime Minister David Cameron and made his case for the UK to remain inside the European Union Getty Images David Cameron's premiership - in pictures After David returned from Brussels claiming victory in his renegotiation with European leaders, Boris Johnson announced that he will not support the Remain campaign. The prime minister said publicly he was "disappointed but Boris remains a friend" PA David Cameron's premiership - in pictures Prime Minister David Cameron makes a joint appearance with Mayor of London Sadiq Khan as they launch the Britain Stronger in Europe guarantee card at Roehampton University on 20 May 2016 in London. The 'guarantee card' lists five pledges should Britain remain in the EU, including the protection of workers' rights, full access to the single market and stability for Britain David Cameron's premiership - in pictures Britain's Prime Minister David Cameron speaks outside 10 Downing Street on 24 June 2016. Cameron announced his resignation after Britain voted to leave the European Union after a bitterly divisive referendum campaign AP

“It's impossible in history to write the counter-factual. You don't know what would have happened if Boris hadn't been part of the campaign.

“But my feel, my gut instinct, is that he made a very considerable difference.”