JAKARTA, Indonesia — President Joko Widodo of Indonesia led by a comfortable margin in unofficial returns in his re-election bid on Wednesday, as he appeared to fend off a challenge by a four-time presidential candidate supported by hard-line Islamists.
Mr. Joko, who is seeking a second five-year term, has made expanding social programs and building roads, airports, seaports and transit lines high priorities, and his approach appeared to be paying off with voters across the sprawling archipelago.
His opponent, Prabowo Subianto, tried to win popular support by attacking “evil elites” who he said had undermined the country. Mr. Prabowo was once married to a daughter of Suharto, the dictator who ruled Indonesia for three decades up to 1998, and he was dismissed from the army decades ago for ordering his troops to kidnap activists.
Unofficial vote counts had Mr. Joko leading by roughly 10 percentage points. Official ballot counts in the far-flung island nation always take weeks, but the winner usually becomes apparent hours after the voting through so-called quick counts, in which independent polling firms tally ballots from a sampling of polling places nationwide.
If Mr. Joko wins as expected, he will continue to face daunting challenges in his second term, including the threat of Islamic terrorism, frequent natural disasters, and raising the standard of living for the sprawling country’s huge impoverished population.
Mr. Joko addressed reporters late Wednesday afternoon but stopped short of claiming victory based on the quick count that was still in progress.
“We have seen the results but we have to be patient to wait for the official count by the election commission,” he said.
The official election results will be released sometime between April 25 and May 22.
The president also sought to begin national healing from the campaign, which was heated at times.
“Let us go back to unite as brothers and sisters as the same country and nation after this presidential and legislative election,” he said.
During his campaign, Mr. Joko, 57, emphasized infrastructure development while moving to shore up support among traditional Muslims. He was the governor of Jakarta, the capital, before becoming president.
Some critics feared a victory by Mr. Prabowo could turn the clock back toward authoritarian rule.
As a lieutenant general during the Suharto era, Mr. Prabowo, 67, commanded the feared Special Forces and was later dismissed from the army for insubordination and the kidnapping of at least nine activists who opposed his father-in-law’s rule.
To counter Mr. Prabowo’s appeal to such Muslims, Mr. Joko named a conservative cleric, Ma’ruf Amin, as his running mate and made a pilgrimage to Mecca this week to remind voters of his piety.
At a polling station in central Jakarta, Trianasari Arief, 44, said she was excited to vote for Mr. Joko and wanted to do her part to keep Mr. Prabowo from winning. She said the ex-general, known for his quick temper and unpredictable behavior, reminded her of President Trump and his upset victory in 2016.
“I don’t want what happened in the United States to happen in Indonesia — where people don’t go to vote and they get the orange-skin guy into office,” Ms. Trianasari said.
But Mr. Prabowo’s anti-elitist message did win favor among some voters. Sri Lestari, 42, a nanny in the affluent Menteng neighborhood, said Mr. Joko had not done enough to bring fairness to the judicial system, resolve human rights cases or unify the people.
“I want a leader who is firm and has high integrity, who is independent, not steered by other people and can make a decision on his own,” she said.
Even with a victory by Mr. Joko, commonly known as Jokowi, the long-term trend toward increasingly conservative Islam in Indonesia is expected to continue.
“Before we knew the election results, regardless of who was going to win, we knew the influence of conservative Islam was going to grow,” said Douglas Ramage, the Jakarta-based managing director of BowerGroupAsia, a business consulting firm.
That is in part because Mr. Joko’s choice of running mate, an influential 76-year-old cleric, Ma’ruf Amin, can be expected to play a significant role as vice president if the ticket wins.
Mr. Ramage noted that Mr. Joko was very successful in carrying out the agenda he promised in his first campaign, such as expanding health and education programs and building infrastructure, earning about 70 percent approval in recent opinion polls.
But only about 55 percent said they would support him for another term because he had not done enough to promote expanding the role of Islam in daily life.
“The most conspicuous manipulation of religion for political purposes came from the opponents,” Mr. Ramage said. “But even under a re-elected President Jokowi, Indonesia continues to move to the right.”
At a time when many Southeast Asian countries have become autocratic, Indonesia remains one of the most democratic.
About 190 million people were eligible to vote in an election that employed six million temporary poll workers. To prevent undue influence, members of the military and the police — more than 800,000 people — were barred from voting.
The quick-count method, which has been highly accurate in past elections, is based on sampling about 2,500 selected polling stations out of more than 800,000.
Because all votes are counted at each polling station in full view of the public, the quick count is based on actual votes cast, not the report of voters as the leave their polling places, known as exit polls, which are commonly used in the United States.
Mr. Prabowo also addressed reporters in the afternoon and said that his campaign’s exit polling and quick count showed him leading, with him capturing 52 to 55 percent of the vote in the two-way race.
He had threatened earlier, if he was declared the loser, to challenge the legitimacy of the vote and claim that the results were tainted by irregularities, an accusation he has made after previous defeats.
But on Wednesday he urged his followers not to take action based on the reports that Mr. Joko was winning.
“Everyone should stay calm and remain unprovoked from committing anarchy,” he said. “Focus on safeguarding the ballot boxes, because they hold the key to our victory, so that the lies that have been committed can be fought.”