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.