The UK's ambassador to the European Union urged staff to "challenge ill-founded arguments and muddled thinking" over Brexit as he resigned.

Sir Ivan Rogers unexpectedly stepped down with weeks to go before Theresa May was due to trigger the process of leaving the 28-nation bloc.

Here is his shock resignation letter in full.

2016: The year of Brexit

Sir Ivan Roger's message to civil servants in full

Dear All,

Happy New Year! I hope that you have all had/are still having, a great break, and that you will come back refreshed and ready for an exciting year ahead.

I am writing to you all on the first day back to tell you that I am today resigning as Permanent Representative.

As most of you will know, I started here in November 2013. My four-year tour is therefore due to end in October – although in practice if we had been doing the Presidency my time here would have been extended by a few months.

As we look ahead to the likely timetable for the next few years, and with the invocation of Article 50 coming up shortly, it is obvious that it will be best if the top team in situ at the time that Article 50 is invoked remains there till the end of the process and can also see through the negotiations for any new deal between the UK and the EU27.

It would obviously make no sense for my role to change hands later this year.

I have therefore decided to step down now, having done everything that I could in the last six months to contribute my experience, expertise and address book to get the new team at political and official level under way.

This will permit a new appointee to be in place by the time Article 50 is invoked.

Importantly, it will also enable that person to play a role in the appointment of Shan's replacement as DPR. [Shan Morgan his deputy]

I know from experience - both my own hugely positive experience of working in partnership with Shan, and from seeing past, less happy, examples - how imperative it is that the PR and DPR operate as a team, if UKREP is to function as well as I believe it has done over the last few years.

I want to put on record how grateful I am to Shan for the great working relationship we have had.

She will be hugely missed in UKREP, and by many others here in Brussels, but she will be a tremendous asset to the Welsh government.

From my soundings before Christmas, I am optimistic that there will be a very good field of candidates for the DPR role.

But it is right that these two roles now get considered and filled alongside each other, and for my successor to play the leading role in making the DPR appointment.

I shall therefore stand aside from the process at this point.

Brexit Concerns Show all 26 1 /26 Brexit Concerns Brexit Concerns Brexit will put British patients at 'back of the queue' for new drugs Brexit will put British patients at the “back of the queue” for vital new drugs, the Government has been warned – forcing them to wait up to two years longer A medicines regulator has raised the alarm over a likely decision to pull out of the European Medicines Agency (EMA), as well as the EU itself. ealth Secretary Jeremy Hunt dropped the bombshell , when he said he expected the UK would quit the EMA – because it is subject to rulings by the European Court of Justice. Getty Images Brexit Concerns London to lose status as 'gateway to Europe' for banks One of Germany’s top banking regulators has warned that London could lose its status as “gateway to Europe” for the banking sector after Britain quits the European trading bloc. Andreas Dombret, who is an executive board member for the Bundesbank—Germany’s central bank—told a private meeting of German businesses and banks earlier this week in Frankfurt that even if banking rules were “equivalent” between the UK and the rest of the EU, that was still “miles away from [Britain having] access to the single market”, the BBC reports. Jason Hawkes Brexit Concerns Exodus The number of financial sector professionals in Britain and continental Europe looking for jobs in Ireland rocketed in the months after the UK voted to leave the European Union Shutterstock Brexit Concerns Brexit is making FTSE 100 executives richer Pay packages of many FTSE 100 chief executive officers are partly tied to how well share prices are doing rather than the CEO’s performance -- and some stocks are soaring. ritish equities got a boost since the June vote because the likes of Rio Tinto, Smiths Group and WPP generate most sales abroad and earn a fortune when they convert these revenues back into the weakened pound. Sterling’s fall also made UK stocks more affordable for overseas investors. Rex Brexit Concerns Theresa May: UK to leave single market Theresa May has said the UK "cannot possibly" remain within the European single market, as staying in it would mean "not leaving the EU at all". Getty Brexit Concerns Lead campaigner Gina Miller and her team outside the High Court Getty Brexit Concerns Raymond McCord holds up his newly issued Irish passport alongside his British passport outside the High Court in Belfast following a judges dismissal of the UK's first legal challenges to Brexit PA wire Brexit Concerns SDLP leader Colum Eastwood leaving the High Court in Belfast following a judges dismissal of the UK's first legal challenges to Brexit PA wire Brexit Concerns Migrants with luggage walk past a graffiti on a wall as they leave the 'Jungle' migrant camp, as part of a major three-day operation planned to clear the camp in Calais Getty Brexit Concerns Migrants leave messages on their tents in the Jungle migrant camp Getty Brexit Concerns The Adventist Development and Relief Agency (Adra) which distributes approximately 700 meals daily in the northern Paris camp states that it is noticing a spike in new migrant arrivals this week, potentially linked the the Calais 'jungle' camp closure - with around 1000 meals distributed today EPA Brexit Concerns Migrant workers pick apples at Stocks Farm in Suckley, Britain Reuters Brexit Concerns Many farmers across the country are voicing concerns that Brexit could be a dangerous step into the unknown for the farming industry Getty Brexit Concerns Bank of England governor Mark Carney who said the long-term outlook for the UK economy is positive, but growth was slowing in the wake of the Brexit vote PA Brexit Concerns The Dow Jones industrial average closed down over 600 points on the news with markets around the globe pluninging Getty Brexit Concerns Immigration officers deal with each member of the public seeking entry into the United Kingdom but on average, 10 a day are refused entry at this London airport and between 2008 and 2009, 33,100 people were detained at the airport for mainly passport irregularities Getty Brexit Concerns A number of global investment giants have threatened to move their European operations out of London if Brexit proves to have a negative impact on their businesses Getty Brexit Concerns Following the possibility of a Brexit the UK would be released from its renewable energy targets under the EU Renewable Energy Directive and from EU state aid restrictions, potentially giving the government more freedom both in the design and phasing out of renewable energy support regimes Getty Brexit Concerns A woman looking at a chart showing the drop in the pound (Sterling) against the US Dollar in London after Britain voted to leave the EU Getty Brexit Concerns Young protesters outside the Houses of Parliament in Westminster, to protest against the United Kingdom's decision to leave the EU following the referendum Getty Brexit Concerns Applications from Northern Ireland citizens for Irish Passports has soared to a record high after the UK Voted in favour of Leaving the EU Getty Brexit Concerns NFU Vice President Minette Batters with Secretary of State, Andrea Leadsome at the National Farmers Union (NFU) took machinery, produce, farmers and staff to Westminster to encourage Members of Parliament to back British farming, post Brexit Getty Brexit Concerns The latest reports released by the UK Cabinet Office warn that expats would lose a range of specific rights to live, to work and to access pensions, healthcare and public services. The same reports added that UK citizens abroad would not be able to assume that these rights will be guaranteed in the future Getty Brexit Concerns A British resident living in Spain asks questions during an informative Brexit talk by the "Brexpats in Spain" group, about Spanish legal issues to become Spanish citizens, at the town hall in Benalmadena, Spain Reuters Brexit Concerns The collapse of Great Britain appears to have been greatly exaggerated given the late summer crowds visiting city museums, hotels, and other important tourist attractions Getty Brexit Concerns The U.K. should maintain European Union regulations covering everything from working hours to chemicals until after the government sets out its plans for Brexit, said British manufacturers anxious to avoid a policy vacuum and safeguard access to their biggest export market Getty

I know that this news will add, temporarily, to the uncertainty that I know, from our many discussions in the autumn, you are all feeling about the role of UKREP in the coming months and years of negotiations over “Brexit”.

I am sorry about that, but I hope that it will help produce earlier and greater clarity on the role that UKREP should play.

My own view remains as it has always been. We do not yet know what the government will set as negotiating objectives for the UK's relationship with the EU after exit.

There is much we will not know until later this year about the political shape of the EU itself, and who the political protagonists in any negotiation with the UK will be.

But in any negotiation which addresses the new relationship, the technical expertise, the detailed knowledge of positions on the other side of the table - and the reasons for them, and the divisions amongst them - and the negotiating experience and savvy that the people in this building bring, make it essential for all parts of UKREP to be centrally involved in the negotiations if the UK is to achieve the best possible outcomes.

Serious multilateral negotiating experience is in short supply in Whitehall, and that is not the case in the Commission or in the Council.

The government will only achieve the best for the country if it harnesses the best experience we have - a large proportion of which is concentrated in UKREP - and negotiates resolutely.

Senior ministers, who will decide on our positions, issue by issue, also need from you detailed, unvarnished - even where this is uncomfortable - and nuanced understanding of the views, interests and incentives of the other 27.

The structure of the UK's negotiating team and the allocation of roles and responsibilities to support that team, needs rapid resolution.

The working methods which enable the team in London and Brussels to function seamlessly need also to be strengthened.

The great strength of the UK system - at least as it has been perceived by all others in the EU - has always been its unique combination of policy depth, expertise and coherence, message co-ordination and discipline, and the ability to negotiate with skill and determination.

UKREP has always been key to all of that. We shall need it more than ever in the years ahead.

As I have argued consistently at every level since June, many opportunities for the UK in the future will derive from the mere fact of having left and being free to take a different path.

But others will depend entirely on the precise shape of deals we can negotiate in the years ahead.

Contrary to the beliefs of some, free trade does not just happen when it is not thwarted by authorities: increasing market access to other markets and consumer choice in our own, depends on the deals, multilateral, plurilateral and bilateral that we strike, and the terms that we agree.

I shall advise my successor to continue to make these points.

Meanwhile, I would urge you all to stick with it, to keep on working at intensifying your links with opposite numbers in DEXEU [Department for Exiting the EU] and line ministries and to keep on contributing your expertise to the policy-making process as negotiating objectives get drawn up.

The famed UKREP combination of immense creativity with realism ground in negotiating experience, is needed more than ever right now.

On a personal level, leaving UKREP will be a tremendous wrench. I have had the great good fortune, and the immense privilege, in my civil service career, to have held some really interesting and challenging roles: to have served four successive UK prime ministers very closely; to have been EU, G20 and G8 Sherpa; to have chaired a G8 Presidency and to have taken part in some of the most fraught, and fascinating, EU negotiations of the last 25 years - in areas from tax, to the MFF to the renegotiation.

Of all of these posts, I have enjoyed being the Permanent Representative more than any other I have ever held.

That is, overwhelmingly, because of all of you and what you all make UKREP: a supremely professional place, with a fantastic co-operative culture, which brings together talented people whether locally employed or UK-based and uniquely brings together people from the home civil service with those from the Foreign Office.

UKREP sets itself demanding standards, but people also take the time to support each other which also helps make it an amazingly fun and stimulating place to work.

I am grateful for everything you have all done over the last few years to make this such a fantastic operation.

For my part, I hope that in my day-to-day dealings with you I have demonstrated the values which I have always espoused as a public servant.

I hope you will continue to challenge ill-founded arguments and muddled thinking and that you will never be afraid to speak the truth to those in power.

I hope that you will support each other in those difficult moments where you have to deliver messages that are disagreeable to those who need to hear them.

I hope that you will continue to be interested in the views of others, even where you disagree with them, and in understanding why others act and think in the way that they do.

I hope that you will always provide the best advice and counsel you can to the politicians that our people have elected, and be proud of the essential role we play in the service of a great democracy.