Bangladesh chose to field and quickly had the hosts in trouble. Jordan Hermann fell for seven, Quinton de Kock made 27 off 15 balls, Sinethemba Qeshile scored 20 off 13, and Dewald Brevis was back in the hut for a two-ball duck.
When Qeshile fell at 57/4 after 6.3 overs, neither Pretorius nor Stubbs had faced a delivery.
They began rebuilding and added 44 when rain interrupted play with South Africa on 101/4 after 16 overs.
Once play resumed, the pair continued to build the innings before steadily increasing the scoring rate.
Their partnership passed 100 at 157/4 and 200 at 257/4, eventually reaching 237 as they carried South Africa from 57/4 to 294/5.
Pretorius, who was the more aggressive of the partnership, brought up his maiden ODI century from 92 balls and went on to make 124 off 114, with 12 fours and three sixes.
At 20 years and 252 days, he also became the youngest player in men's international cricket to record three-figure scores in all three formats.
Stubbs reached his half-century more cautiously before accelerating. He brought up his century from 117 balls and finished with 136 off 131, including six fours and six sixes.
Pretorius was dismissed by Tanvir Islam at 294/5, but the Dafabet Warriors captain and all-rounder continued the assault with the lower order.
The hosts added 63 runs after Pretorius' dismissal before Stubbs was run out for 136 at 355/8 with one ball remaining.
His innings surpassed Saleem Elahi's previous St George’s Park ODI record of 135, while SA’s 357/8 overtook Pakistan's 335/6 from 2002 as the highest men's ODI total at the venue.
Mustafizur Rahman finished with 4/94 for Bangladesh and Tanvir Islam took 2/60.
The tourists' chase began with a similar collapse as Anrich Nortje and Nqobani Mokoena reduced them to 56/4 inside 12 overs.