Image copyright Reuters Image caption South African finance minister Pravin Gordhan

South Africa has avoided losing its investment grade credit rating from Standard & Poor's, but the agency has maintained its negative outlook.

S&P held the country's sovereign debt rating at BBB- but warned about the consequences of low economic growth.

It had been feared the agency would cut South Africa to so-called "junk status", making it more expensive to borrow.

The rand extended gains to rise 3% against the dollar.

Finance minister Pravin Gordhan said it was "important to create optimism in our economy and our country and stop making negative noises which harms us not just in the eyes of global investors, but the global public as well".

A cut to "junk" status would have made borrowing more expensive for Pretoria, making it harder to plug a budget deficit estimated at 3.2% of GDP for the 2016-17 financial year.

Last month Moody's made the unexpected decision to upgrade South Africa's rating to a position two notches above "junk".

However, the agency also maintained a negative outlook, meaning that a cut could come when it next reviewed the situation.

Analysis: Lerato Mbele, Africa Business Report presenter

In deciding to keep South Africa a notch or two above "junk" status, both Moody's and S&P are throwing South Africa a lifeline. The ratings agencies' message is simple - get things right or suffer the consequences.

Both have given differing reasons, but they agree on one issue: that the South African economy is not as attractive or stable as it previously was.

To assess whether there is general consensus on how bad things are, the investment community will be waiting for Fitch's announcement later this month.

If South Africa wants to preserve its sovereign credit rating, it must take bold actions quickly.

Otherwise the near future is one of a downgrade to "junk" status, which will lead to reputational damage, higher borrowing costs, disinvestment, the decline in the value of pension funds and make life more expensive for its citizens.

South Africa has not been below investment grade since 1994.

In December, S&P revised its outlook on South Africa's rating from stable to negative, citing fears that economic growth might be lower than expected.

Last month, the International Monetary Fund cut its 2016 forecast for South Africa to 0.6%, from 0.7%. The economy expanded by 1.3% in 2015.