The U.S. credit ratings agency raised Indonesia's rating from BB+ to BBB-, one notch above junk status, with a stable outlook. The decision means Indonesia's debt is investment grade according to all three major credit ratings agencies, the others being Fitch Ratings and Moody's Investor Service.

"The Indonesian authorities have taken effective expenditure and revenue measures to stabilize the country's public finances despite the terms of trade shock," S&P said. "As a result, we expect net general government debt will stabilize near the current low levels, while the budget deficit will gradually decline."

The announcement is a much-needed boost for Widodo's government, which has slashed gasoline subsidies and embarked on a nine-month tax amnesty to boost revenue since he took office in October 2014. S&P also said the government's "new focus on realistic budgeting" limits the risk of a widening budget deficit.

It will also give some breathing room to the president, who is under pressure to quiet the political turmoil that has arisen since the Jakarta gubernatorial election in April. The incumbent, Gov. Basuki Tjahaja Purnama, a Christian better known as Ahok, was recently sentenced to two years in prison for blasphemy. That move has polarized the country and worried investors.

The rating upgrade "could allow Indonesia to access a pool of eligible foreign investors that only invests in at least [investment grade]-rated assets, lowering funding costs," said Trinh D. Nguyen, an economist at Natixis.

Indonesia's benchmark stock market index hit a record high following the announcement and ended the session Friday up 2.6%. The rupiah also rallied against the dollar.