The surplus was the widest on record, topping the record seen in June last year and well above a market forecast of R25bn.
Exports increased by 28.9% on a month-on-month basis to R168.29bn, while imports rose 16.3% to R115.52bn, the revenue Service said.
Sales in the precious metals and stones category climbed 41% in the month, followed by a 22% jump in mineral exports and 32% increase in vehicle exports.
Some analysts are predicting that the current boom in commodity prices may be the beginning of a commodities supercycle, like the one seen in the early 2000s, driven by the release of pent-up demand, especially from China.
Global gold, platinum and copper prices have hit record highs in 2021. The first two are among South Africa's chief exports.
"South Africa now surprises with what may be the most positive trade print versus consensus in the history of this series," said Razia Khan, chief Africa economist at Standard Chartered Bank.
"It would be wrong to attribute this to a weak economy. Given our expectations of firm PGM prices, the good news is likely here to stay. This should provide significant support to the rand," Khan said.
The rally in global commodity prices saw South Africa collect more tax revenue than expected, easing pressure on an economy that was in recession before Covid-19 struck, and in 2020 suffered its biggest slump in a century.