Image caption Lord O'Donnell served three prime ministers as cabinet secretary

Britain would be unable to negotiate its exit from the EU within the two years allowed by European Union rules, the former Cabinet Secretary Lord O'Donnell has said.

The prospect of demanding extra time from other EU nations to complete a leave deal was a "bit scary", he said.

Asked how long a negotiation would take, he cited a Cabinet Office paper which said it could be up to a decade.

But Out campaigners say the UK could negotiate its withdrawal at any time.

The UK will decide in a referendum on 23 June whether to remain a member of the European Union or to leave.

EU vote: All you need to know

Under the process set out in the Lisbon Treaty, a nation has two years to complete a deal once it formally declares that it will withdraw from the EU.

'Very difficult'

Extra time is possible only if all the remaining nations agree.

"Obviously at the end of two years anything we haven't negotiated has to be extended by unanimity of a vote excluding us so that's a bit scary," Lord O'Donnell - who advised three successive prime ministers as cabinet secretary between 2005 and 2011 - told BBC Radio 4's Today programme.

"I'm in that camp that doesn't think we can do it in two years," he said, adding that negotiating a deal to leave was a "very complex process".

Reality Check: Could Brexit be negotiated in two years?

A leave vote on 23 June would not immediately part the UK and the European Union.

First, they would have to decide what their relationship would be like in the immediate future.

Once Britain formally tells the European Council it is leaving, it has two years to negotiate the terms of its withdrawal. Extra time would only be allowed if the remaining 27 states all agreed.

Lord O'Donnell fears complex talks would take much longer than that, and if the EU refused an extension to the negotiating period, the UK could face higher trade tariffs.

But - the clock would only start once Britain formally notified the European Council. Read more.

He said: "We have to negotiate our entry to the single market, we have to negotiate our future relationship with the EU and then we have to negotiate our trade treaties with all other countries. So there's a lot to be done."

He told Today the Article 50 rules on the process were "not written in a neutral way" and warned it would be a "rather biased playing field".

It could also be "very difficult" to achieve positive results with Germany and France facing elections in 2017, he said.

"The politics works completely the wrong way for us", he added.

If the UK failed to get a deal within two years, the country would revert to World Trade Organization rules, which would include significant tariffs, he added.

'Smaller than Croydon'

Greenland's decision to withdraw from the European Community, the organisation that preceded the EU, in 1985 offered the only precedent, he said.

"Greenland has a slightly smaller population than Croydon and it has one issue, and that's fish," he said.

"So with one issue, small population, it took them not two years but three. We have multiple issues. The idea that we can do it all in two years I think is highly unlikely."

Image copyright HoC Image caption Mr Raab says there is "no doubt" the UK would negotiate a new relationship with the EU

While Lord O'Donnell did not declare himself a supporter of the Remain campaign, his argument was very similar to the government's - whose position is to remain in the union.

The Vote Leave campaign, a cross-party group campaigning for EU exit, rejects the idea that negotiations would have to take place along the lines set out in the European Treaty. It says the UK could negotiate its withdrawal at any time without triggering the formal process.

Lord O'Donnell's comments come as Out campaigners step up their warnings about what they say are the risks to UK security of remaining in the EU.

Justice Minister Dominic Raab used a speech in London to argue being in the EU makes it harder for the UK to stop serious criminals and those with suspected terror links entering the country.

Speaking to the Today programme, Mr Raab rejected Lord O'Donnell's argument.

He said the former civil service boss was not a diplomat or an international lawyer, adding: "I used to negotiate treaties and I can tell you that if we voted to leave we could do so and negotiate an exit agreement."

He said the UK was the fifth biggest economy in the world and a key export market for the EU: "Of course we'd strike a new deal, and relatively soon, with transitional arrangements if necessary."