LONDON — Prime Minister David Cameron announced his resignation Friday morning after British voters defied his advice and decided to pull their country out of the European Union.

Cameron said he would remain in his post for a few more months to “steady the ship” until a successor can take over and lead Britain’s negotiations with the E.U. on the specifics of its exit from the 28-nation trading bloc. He said he expected a new prime minister to be in place by October.

“The British people have made a very clear decision to take a different path, and as such I think the country requires fresh leadership to take it in this direction,” Cameron said in a somber statement delivered outside of 10 Downing St. “I will do everything I can as prime minister to steady the ship over the coming weeks and months, but I do not think it would be right for me to try to be the captain that steers our country to its next destination. This is not a decision I’ve taken lightly, but I do believe it’s in the national interest to have a period of stability and then the new leadership required.”

It was a spectacular political downfall for Cameron, 49, who had expected to serve out his second term as prime minister, until 2020, which would complete a decade in power. But after the results of Thursday’s “in or out” referendum became clear – 52% of voters opted to leave the E.U. – Cameron’s authority was irretrievably diminished. Commentators said the question was not whether he would step down from office but when.

In many ways, it was a self-inflicted injury: Cameron himself called the referendum in order to appease the “Euroskeptics” in his Conservative Party who wanted out of the E.U. He was confident of convincing the electorate to vote to remain, and the polls in the beginning supported his view.

But the “Leave” camp kept up a relentless barrage of criticism of the influx of European migrants into Britain, which Cameron was powerless to stop under E.U. rules. Critics also accused Cameron of fear-mongering with his warnings of economic Armageddon if Britain withdrew.

But even as he announced his resignation Friday morning, the London stock exchange was suffering heavy losses, and the British pound was flirting with a 30-year low against the dollar. Mark Carney, chairman of the Bank of England, made a statement shortly afterward pledging to take strong measures to protect the pound.

Cameron and Carney both sought to reassure Brits and investors alike that nothing had changed overnight in practical terms. Unwinding British membership in the E.U. is a process that will probably take at least two years, and until the terms are agreed upon, Britain is still considered a member of the bloc.

That means that the free movement of people and goods within the E.U., including Britain, remains in place. Europeans are still able to come to Britain to live and work without restrictions, and Britons residing visa-free in other E.U. countries can continue their lives as usual.

Cameron said he would leave it to his successor to formally invoke “Article 50,” the E.U. provision that triggers a member state’s process of withdrawing. That would then initiate the negotiations over the exit terms.

Top E.U. officials called on Britain to begin exit negotiations as quickly as possible, saying any delay would “unnecessarily prolong uncertainty.”

One possible successor to Cameron is former London Mayor Boris Johnson, who campaigned for Britain to leave the E.U. He insisted Friday that his country was not turning its back on Europe — just the “supra-national” European Union.

“Britain will continue to be a great European power, leading discussions on foreign policy, on defense and intelligence-sharing, and all the work that currently goes on to make our world safer,” Johnson said. “But there is simply no need in the 21st century to be part of a federal system of government based in Brussels that is imitated nowhere else on Earth.”