S&P however kept its negative outlook for South Africa, which has struggled with political friction under President Jacob Zuma, high unemployment and slow growth.
"Political events have distracted from growth-enhancing reforms, while low GDP growth continues to affect South Africa's economic and fiscal performance," S&P warned.
"The negative outlook reflects the potentially adverse consequences of persistently low GDP growth."
But the agency lowered South Africa's local currency rating to two notches above junk in a further sign of concern over the country's economic prospects.
The Fitch ratings firm last week kept South Africa one notch above junk, but dropped its outlook from stable to negative.
Also last week, Moody's kept South Africa unchanged two notches above junk status.
The treasury welcomed S&P's announcement, saying it "was as a result of working together as South Africans to ensure that the country remains an investment grade."
"The work remains, but together, we will continue to work hard to build a foundation for faster growth."
Keeping the investment grade rating is important as many foreign pension and investment funds are barred from buying bonds that are rated as speculative or junk. Losing the investment grade rating also usually means a country has to pay more to borrow.
This week has seen further political drama when Zuma's loyalists beat back an attempt by at least four ministers to oust him from power.
The rebellion was the most serious threat to the president since he took office in 2009.
Zuma has been engulfed by graft scandals, while South Africa's economic growth has fallen to 0.5 percent and unemployment hit a 13-year high.
Efforts to avoid junk status have been at the centre of political wrangling for months, with Zuma at loggerheads with Finance Minister Pravin Gordhan, a reformist widely respected among international investors.
Gordhan had been due to appear in court last month on graft charges that many experts saw as an attempt by Zuma associates to oust him.
Gordhan was appointed only last year to calm panicked investors when Zuma sacked two finance ministers within four days.
"We could lower the ratings if we believed that institutions had become weaker due to political interference affecting the government's policy framework," S&P added in its announcement.
The ruling ANC party is due to elect a new leader at the end of next year, ahead of the 2019 general election when Zuma must stand down after serving two terms.
South Africa last month unveiled the proposed figure for its first minimum wage -- 3,500 rand ($242) a month -- in a move that could improve labour relations.
Fitch, which said South Africa's banking sector "remains a rating strength", forecast GDP growth of 1.3 percent in 2017 and 2.1 percent in 2018.