ANKARA, Turkey – Soaring inflation left his people feeling poorer. His government was accused of botching its response to catastrophic earthquakes that killed more than 50,000 people just three months ago. And he faced a newly unified opposition that promised to reverse his steady drift toward one-man rule.

Despite all of that, President Recep Tayyip Erdogan came out with a lead over his main challenger in Turkish elections, according to official results released on Monday. Though he fell just short of an outright majority, sending the nation to a runoff on May 28, there are strong signs pointing to yet another Erdogan victory in that vote.

“For Erdogan, this is his greatest finale,” said Mehmet Ali Kulat, a prominent Turkish pollster who had foreseen a stronger showing by the opposition.

With nearly all of the ballots counted on Monday, official preliminary results gave Mr. Erdogan 49.5 percent of the vote versus 44.9 percent for his main challenger, opposition leader Kemal Kilicdaroglu. A third candidate, Sinan Ogan, received 5.2 percent, and his right-wing supporters are more likely to vote for Mr. Erdogan in the runoff, analysts say. Finally, Mr. Erdogan’s party and its allies maintained a commanding majority in the parliamentary vote, likely further increasing his ability to be re-elected.

Many Turkish news outlets are owned by pro-Erdogan businessmen, ensuring that they provided a steady stream of exultant coverage, with little attention paid to corruption allegations or government mistakes. The government has forced some news organizations critical of it to shut down, fined others for their coverage, and prosecuted some journalists. The group Reporters Without Borders ranks Turkey 165th in press freedom out of 180 countries it grades.

The opposition did not officially acknowledge Mr. Erdogan’s lead or contest the figures, but said they would work to win the runoff.

“We will stand up and take this election together,” Mr. Kilicdaroglu wrote on Twitter on Monday. “At the end of everything, it will only be what our nation says.”

In his 20 years as Turkey’s dominant political leader, first as prime minister, then as president, Mr. Erdogan and his Justice and Development Party have regularly trounced their opponents at the ballot box. The last time, Mr. Erdogan stood for election in 2018, he won 52 percent of the vote in the first round, beating the closest of his three challengers by 22 percentage points. He fared worse this time, prompting the first presidential runoff in Turkish history.

Voter turnout across the country on Sunday was nearly 89 percent, underlining the great faith Turks put in elections.

Mr. Erdogan faced considerable headwinds going into the vote.

Turkey has been struggling since 2018 with a sinking currency and painful inflation that exceeded 80 percent annually last year and stood at 44 percent in April.

His opponents pulled together in an unprecedented coalition of six parties that backed Mr. Kilicdaroglu. Throughout the campaign, the opposition courted voters by promising to fix the economy, restore civil liberties and build a more inclusive society, a stark contrast to Mr. Erdogan’s often polarizing rhetoric.

But that wasn’t enough.

Analysts described the results as just the latest example of Mr. Erdogan’s formidable survival skills.

Mr. Kulat said that the Feb. 6 earthquakes had actually helped Mr. Erdogan in unexpected ways. The vast destruction not only left huge numbers of people homeless but put pressure on communities outside of the afflicted area by driving up rent prices. That increased the attraction of Mr. Erdogan’s campaign promises to build new homes across the quake zone in one year.

“The citizens said, ‘If anyone can build me a house, it is Erdogan,’” Mr. Kulat said.

But Mr. Erdogan also used his power to tilt the competition in his favor. And as the incumbent in a system with few checks on presidential power, Mr. Erdogan effectively used the state as his campaign apparatus, doling out new benefits to voters from the national purse.

Mr. Erdogan campaigned by dismissing his opponents as incompetent, supported by a Western conspiracy and in cahoots with terrorists. He sought opportunities to link himself in voters’ minds with images of growing Turkish might and independence, parking a warship in central Istanbul for families to visit and becoming the first owner of a Turkish-built electric car.

And he and his ministers sold him as the defender of religious Turks, stoking their fears by telling them that the opposition sought to take away their newfound freedoms and expand gay rights. While a predominately Muslim society, Turkey was founded as a staunchly secular state that kept most outward signs of religion out of public life. Mr. Erdogan loosened some of those rules, including a ban on women in state jobs wearing head scarves.

Those issues appeared to have kept enough voters on board to give Mr. Erdogan the lead.

“Political identification is very ‘sticky,’ and doesn’t easily come undone because of new information or experience,” Howard Eissenstat, an associate professor of history at St. Lawrence University, wrote in an email. “Erdogan’s emphasis on nationalism, terrorism and nefarious Western plots isn’t window dressing for many voters: it is at the core of their worldview.”

In contrast to what Mr. Erdogan could deliver to voters, the opposition could only offer promises.

To build his support, Mr. Kilicdaroglu pulled together six parties that include right-wing nationalists, staunch secularists and Islamists, a feat in itself. But many voters questioned how such a broad coalition would stick together, much less run the country.

“Despite frustration with the economy and the earthquakes’ effects, a lot of people didn’t think an opposition coalition — particularly one with internal ideological divides and personal power struggles — would be able to govern effectively,” said Lisel Hintz, an assistant professor of international relations at Johns Hopkins University’s School of Advanced International Studies.

That Mr. Kilicdaroglu hails from a religious minority probably also turned some voters away, Ms. Hintz said. He is an Alevi, a member of a heterodox Muslim sect that is looked down upon by some members of Turkey’s Sunni Muslim majority.

“It is likely the case that some Sunnis did not want to vote for an Alevi,” Ms. Hintz said.

While no voters interviewed in recent weeks openly expressed such sentiments, many voiced concerns about a different minority group, criticizing the opposition for working with Turkey’s main pro-Kurdish party, equating that to allying with terrorists.

Turkey has fought a long and deadly battle against Kurdish militants that Turkey, the United States and the European Union consider terrorists. The Turkish government often accuses Kurdish politicians of cooperating with the militants, and many of them have been jailed, prosecuted or removed from office because of such allegations.

Mr. Erdogan has played on fears of such links, and many voters see the opposition as sympathetic to militancy.

“I am worried that the other side will win and that would be bad for the country,” Melike Kurt, a recent university graduate, said after voting for Mr. Erdogan on Sunday. She specifically mentioned concern that people jailed on terrorism-related charges would be released.

As a devout woman who wore a head scarf, she also praised Mr. Erdogan for standing up for women like her to dress as they wished, and worried that an opposition government would rescind those rights in the name of state secularism.

“I can’t imagine what kind of situation we’d be in if we lose,” said Ms. Kurt, 24. “I believe that our freedoms would be limited if they win, in terms of head scarves and other issues.”

Safak Timur contributed reporting from Ankara and Gulsin Harman from Istanbul.