JAKARTA, Indonesia — Joko Widodo, the wildly popular governor of Indonesia’s capital, Jakarta, on Friday received what his supporters had been hoping to see: his party’s blessing to run for president in July.

The opposition Indonesian Democratic Party of Struggle announced on Twitter that Mr. Joko, widely known as Jokowi, would be its presidential candidate. The announcement ended more than a year of speculation over whether the party’s chairwoman, Megawati Sukarnoputri, 67, a former president, would name herself as its candidate or support Mr. Joko, who is 15 years younger.

The party posted photographs online Friday of Mrs. Megawati, accompanied by her daughter, Puan Maharani, a senior party leader and lawmaker, holding a handwritten statement declaring that Mr. Joko had been chosen to run, as well as images of “Jokowi for President” buttons.

A former small-town mayor in Central Java Province, Mr. Joko became a political phenomenon after winning the governorship of Jakarta in September 2012 as an opposition candidate. During the past year, in numerous opinion polls about presidential prospects, he has been the clear leader. But he declined to discuss any presidential aspirations, saying the decision was Mrs. Megawati’s.