LONDON—Britons’ startling vote to leave the European Union rattled financial markets and threatened to weaken an already strained continent, instantly reshaping Britain’s political scene as Prime Minister David Cameron announced he would step down.

With all voting areas counted early Friday, Leave beat Remain 51.9% to 48.1%, in a decision that will sever the U.K.’s ties with the EU after 43 years.

The pound fell more than 11% to its lowest point since 1985 and the outcome triggered steep drops in stock markets and a flight into safe assets such as bonds and gold.

As votes rolled in, a portrait of a deeply polarized nation came into focus. The results pitted London, Scotland and Northern Ireland, where Remain was strong, against most of the rest of the country. Whoever leads the U.K. will face the challenge of uniting a country that is now openly, and roughly evenly, divided over its relationship with Europe.

“The people have voted to leave the European Union, and their will must be respected,” Mr. Cameron said outside his Downing Street office with his wife Samantha by his side. “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.”