Britons quickly started wondering whether Mrs. May would have to resign.
One Conservative lawmaker, Anna Soubry, said on national television that it had been a “dreadful campaign” and would force the prime minister to “consider her position.”
The opposition Labour Party, led by Jeremy Corbyn, was projected to be on track for 262 seats, up 30 from 2015, significantly elevating Mr. Corbyn’s standing after predictions that his party would be further weakened.
“Whatever the final result, we have already changed the face of British politics,” Mr. Corbyn said.
Last month, in an effort to show “just how much is at stake” in the election, Mrs. May acknowledged that even a small loss of seats would amount to a defeat.
“The cold, hard fact is that if I lose just six seats, I will lose this election, and Jeremy Corbyn will be sitting down to negotiate with the presidents, prime ministers and chancellors of Europe,” she wrote in The Daily Mail.
But early on Friday, Mrs. May hinted that her Conservative Party would try to form a government even if it did not have a majority, arguing that Britain needed “a period of stability.”
If the Conservative Party “has won the most seats and probably the most votes, then it will be incumbent on us,” she said.
The Scottish National Party was projected to fall to 35 seats from 56, while the centrist Liberal Democrats were projected to win 12 seats, up four from 2015.
The forecast raised the prospect that neither major party would be able to form a government without help from another party. If a coalition cannot be formed, another election could be in the offing.
And there was a wild card. Northern Ireland’s Sinn Fein party, which won seven seats, said it would not occupy them, in keeping with its longstanding policy. That would lower the threshold for Mrs. May’s party to establish an effective majority.
The former chancellor of the Exchequer, George Osborne, said that for Mrs. May losing a majority would be “completely catastrophic” for her and the Conservative Party. But he added that it was also difficult to see how the Labour Party could put together a coalition government.
“So it’s on a real knife edge,” he said.
Clearly, Britons confounded expectations and the betting markets once again. The uncertainty could complicate Britain’s exit from the European Union, known as Brexit. Negotiations over the withdrawal are scheduled to start in just 11 days. European leaders want a stable, credible British government capable of negotiating, but Mrs. May’s plea to voters for a strong mandate for Brexit failed badly.
The official outcome of the vote may not be known until lunchtime on Friday. But the British pound fell sharply after a national exit poll showing that the Conservatives could lose their majority. Within seconds of the exit poll’s release, the pound lost more than 2 cents against the dollar, falling from $1.2955 to $1.2752.
Simon Hix, a professor of political science at the London School of Economics, said the projections showed the public’s resistance to the complete break from Europe that Mrs. May has championed. Still, Mrs. May was set to win, he asserted. “She hasn’t lost this election,” he said.
But Steven Fielding, professor of political history at the University of Nottingham, said that he was almost speechless at the projections. If they held, he said, Mrs. May “is gone.”
“It’s just a matter of time — even if they have a reduced majority,” he continued. “She asked for a mandate, she expected a strong endorsement, so her judgment is completely under question.”
“She was terrible in the campaign,” he added. “She is primarily the person who will be seen to be responsible for this.”
Kallum Pickering, a senior economist at Berenberg Bank in London, also suggested that Mrs. May was in trouble.
“Even if May manages to cling on to a majority, we see a real risk that her leadership is challenged, especially following an unsuccessful election campaign that has managed to both weaken her personal credibility and make far-left Labour leader Corbyn relevant again,” he said as the votes were being counted.
Given the two terrorist attacks that took place during the campaign, security was tight on Thursday as Britons voted, with a heavy police presence.
Maria Balas, 28, a waitress, said security was the prime issue. “England is under attack and at this time we need a strong leader more than ever,” Ms. Balas said after casting her vote for the governing Conservative Party. “I don’t like Theresa May, and I wouldn’t have bothered to vote if this election was all about giving her more power to take us into the mess of Brexit, but now we are dealing with a security crisis and I think she is the most qualified person in the running who can deal with that.”
In London’s eastern borough of Hackney, however, young people seemed more concerned about future job prospects.
“The Tories only care about the rich and their interests,” said Luke Wright, 26, who earns £7.50 an hour, or about $9.70, working at a stationery shop. “If Labour won I’d have a chance to make more cash and get out of this job that I’m overqualified for.”
Mrs. May, 60, rolled the dice on April 18 when she broke her promise not to call an early election, three years ahead of schedule, but did so only because she believed the dice were loaded in her favor.
She went into this election with a 20-point lead in most polls and a working majority of just 17 seats in the 650-seat House of Commons, the lower house of Parliament.
While she was personally against Britain’s exit from the European Union, or Brexit, in the June 2016 referendum, the vote in favor caused David Cameron to resign, and she emerged as a kind of accidental prime minister.
But she promised voters that she would honor the results of the referendum, using her reputation for toughness “to get the best deal for Britain.”
Now, her decision to call a snap election is raising comparisons to Mr. Cameron’s decision to hold the referendum in the first place.
“May is a policy politician; she does a very good job in office, and she is a lousy campaigner,” said Robert Worcester, the founder of the MORI/Ipsos polling and research organization. “There was just mistake after mistake after mistake coming through.”
Mrs. May pledged to curtail immigration, an effort to reach out to the nearly 13 percent of voters in 2015 who voted for the U.K. Independence Party, whose platform was anti-immigrant and pro-Brexit. Many of those voters, especially in the West Midlands and the north, were traditionally Labour supporters, but with the collapse of UKIP, many of them were thought to lean to the Conservatives.
That meant Labour-held seats seemed ripe for the picking, especially since northerners were not enamored of Mr. Corbyn, 68, a far-left urbanite. He seemed weak on defense and security, shaky on economic management and passionate about places like Venezuela and Nicaragua, and had once had strong sympathies for the Irish Republican Army and liked to make jam.
And the centrist Liberal Democrats, who emphasized rerunning the Brexit debate in a second referendum, were getting very little traction. While the business elite were laser-focused on the issue of Britain’s future relationship with the European Union, opinion polls showed that the general population had moved beyond that and cared more about domestic issues.
Strangely, for such an important issue, the economic impact of Brexit barely figured in this campaign, perhaps because its strongest effects, should they materialize, will not be felt for some time.
Mrs. May and the Conservatives ran an unusually personal campaign, trying to emphasize the differences between her and Mr. Corbyn on questions of leadership, reliability, economic competence and security, helped by the rabidly anti-Corbyn, pro-Brexit tabloid press.
But the Conservatives did not count on her poor performance on television and shaky presence on the campaign trail, particularly when confronted by hostile questioning. Rather than “strong and stable,” as her mantra went, Mrs. May could seem brittle and querulous, repeating slogans rather than dipping into substance.
Her party’s manifesto was also vague on figures, and her effort to find more funds for social benefits backfired when she announced, with little consultation with her cabinet colleagues, her intention to charge the better-off more for extended benefits, saying that old people could keep assets up to 100,000 pounds, including the value of their homes. Quickly labeled “the dementia tax,” it damaged her badly with the Conservatives’ main supporters: older Britons.
“Theresa May doesn’t look happy on the campaign trail,” said Mark Wickham-Jones, professor of political science at the University of Bristol. “And Labour have proved quite effective at chipping away at things like her reluctance to debate.”
At the same time, Mr. Corbyn, who survived an attempt last year by his own members of Parliament to unseat him as Labour leader, had a very good campaign. Appealing to the young, especially in the big cities, Mr. Corbyn ran on a platform promising more social justice, free college tuition, more money for the National Health Service and welfare, the re-nationalization of the railways and utilities, and much higher taxes on corporations and those earning over £80,000, about $104,000, a year.
His performances on television were calm and avuncular, with a touch of humor. And as the campaign wore on, he appeared to win back the support of most Labour voters in 2015, plus some Liberal Democrats and Greens.
The polls narrowed. But the Conservatives never lost their lead in any major poll. And party professionals on the ground, especially in marginal seats in the Midlands and the north that the Conservatives had targeted, reported continuing resistance to Mr. Corbyn as a credible prime minister.
The campaign was also marred by two terrorist attacks that caused numerous casualties, in Manchester on May 22 and then, last Saturday, in London. These also seemed to work against Mrs. May, at least at first. As home secretary for six years before becoming prime minister, she was criticized for the security services’ failure to stop the plots and for supporting cuts in beat policing.
Yet, late polling indicated that she benefited from her tough response — especially after the London attack, when she promised new counterterrorism legislation — and had widened the gap with Labour at the end.
The candidates spent the last day of official campaigning racing around the country — Mrs. May by jet, Mr. Corbyn by train. “They underestimated us, didn’t they?” he told a rally in Glasgow.
An earlier version of this article misstated the number of parliamentary seats held by the Scottish National Party heading into the election. It was 56, not 59.