JAKARTA, Indonesia — Joko Widodo, the governor of Jakarta whose common touch has made him a political phenomenon, was declared the winner of Indonesia’s presidential election on Tuesday, completing an improbable ascent from child of the slums to leader of the world’s fourth-most populous nation.

But the announcement, while widely expected, did not end a simmering controversy. His opponent, Prabowo Subianto, a retired army general, rejected the results as fraudulent and said he was withdrawing from the race.

The General Elections Commission announced that Mr. Joko, with 53 percent of the vote, had beaten Mr. Prabowo, with 47 percent. Nearly 135 million Indonesians cast ballots in the emotionally charged July 9 election, in which voters chose a new president for the first time in 10 years.

There was a huge police presence at the commission’s offices in Jakarta, the Indonesian capital, on Tuesday as the vote tabulations were completed, amid rumors of violent street demonstrations by disappointed supporters of Mr. Prabowo.

As the elections commission was finishing its count and preparing to announce Mr. Joko as the winner, representatives of Mr. Prabowo’s campaign staged a walkout at the commission’s offices. Shortly afterward, Mr. Prabowo read an impassioned statement to supporters at his campaign headquarters, saying he had withdrawn his candidacy and would reject the results.

Image

Mr. Joko is to be sworn in as president on Oct. 20.CreditKemal Jufri for The New York Times

“There has been a massive, structured and systematic fraud,” he said.

But on Tuesday night, his brother and chief adviser, Hashim Djojohadikusumo, said Mr. Prabowo had not in fact withdrawn his candidacy, but was instead demanding additional time for the elections commission to investigate “serious problems” in both ballot casting and vote tabulations.

Commission officials, however, rejected his campaign’s allegations and said a candidate’s withdrawal would have no bearing on the results.

Mr. Hashim said Mr. Prabowo’s campaign team had not yet decided whether to appeal the election results to the Indonesian Constitutional Court.

“We want the K.P.U. to take a serious look at these irregularities,” Mr. Hashim said, referring to the elections commission by its Indonesian abbreviation.

The Constitutional Court has the sole authority to order recounts or new voting at the provincial level and below, and its decisions are binding. The court has two weeks to issue any decision should there be an appeal. But analysts said it was highly unlikely that any ruling would overturn the final national result, given the eight-million-vote margin of Mr. Joko’s victory.

What amounted to declarations of victory by both camps hours after the polls closed led to weeks of uncertainty as the commission tabulated votes from more than 480,000 polling stations. Mr. Joko is to be sworn in Oct. 20. He has pledged to bring more “people-centric” governance and policies to Indonesia, which, despite being a member of the G-20 group of major economies, has more than 100 million people living on $2 a day or less.

The victory represents a striking rise for Mr. Joko, 53, who was born and raised in a riverside slum area in the city of Surakarta, also known as Solo, in Central Java Province. He grew up to be a carpenter and later a furniture exporter before entering politics in 2005. He was twice elected mayor of his hometown, then governor of Jakarta in 2012.

Video

Prabowo Subianto, a retired Indonesian Army general, denounced the result of the country’s presidential election and withdrew his candidacy.Published OnJuly 22, 2014CreditImage by Adi Weda/European Pressphoto Agency

Mr. Joko, a thin, unassuming figure with what he has described as a typical “village face,” will be Indonesia’s seventh president and the first not to have emerged from the country’s political elite or to have been an army general.

Mr. Prabowo, 62, was a son-in-law of Suharto, the authoritarian president who was forced to resign in 1998 after 32 years in power amid pro-democracy street demonstrations. Mr. Prabowo, a successful businessman who comes from a prominent Javanese political family, has a checkered military record, including allegations of human rights abuses as a commander of Indonesia’s Special Forces and later as head of the army’s strategic reserve command. He was denied a visa to enter the United States in 2000 and is believed to be on an unofficial blacklist.

Sitting barefoot inside a small rented house in central Jakarta a few days before Tuesday’s announcement, Mr. Joko said in an interview that Indonesia’s continuing democratic transition had broken the grip of the entrenched political elite on the government. Of crucial importance to this, he said, was the introduction of direct elections from president all the way down to town mayor a decade ago, as part of a national decentralization policy that replaced Suharto’s centralized system of governance.

Mr. Joko will lead a country that has successfully consolidated its democracy and enjoyed strong economic growth under the departing president, Susilo Bambang Yudhoyono, who has served two five-year terms. Indonesia has had one of the fastest-growing economies in Asia in recent years, along with China and India. But that same economy, which achieved annual growth rates of more than 6 percent from 2010 to 2012, mostly thanks to the country’s abundant natural resources and robust domestic consumption, is facing several serious challenges.

They include a trade deficit, a national fuel subsidy that sucks tens of billions of dollars each year from the state budget, inadequate infrastructure, corruption, poverty and a growing disparity between the country’s rich and poor.

During the bruising presidential campaign, Mr. Prabowo characterized Mr. Joko as an unsophisticated, small-town politician who lacked the ability to lead a large nation. But Mr. Joko noted that he would be the only president in Indonesian history to take office with prior experience in running a government.

“It’s about management,” Mr. Joko said. “How to plan, how to organize, how to decide actions. In my opinion, the most important thing in governance is management control.”

Correction:

Because of an editing error, an earlier version of this article referred incorrectly to Central Java. It is a province of Indonesia, not a state.

A version of this article appears in print on , on Page A4 of the New York edition with the headline: A Child of the Slum Rises as President of Indonesia. Order Reprints | Today’s Paper | Subscribe