The 22-year-old came three runs short of becoming the seventh South African to score a hundred on debut, but was involved in a mix-up which led to his run-out on 97 and the end to a fairy tale start to worldwide cricket.
Opener Dean Elgar batted through the opening day for an unbeaten century as South Africa piled on the runs against Bangladesh at Senwes Park on Thursday.
And it is a silently aggressive Hashim Amla who made a better scoring rate hitting his 17th Test hundred from 143 balls.
Hashim Amla completed a 27th Test century before Shafiul Islam had him caught on the off-side boundary playing an uncharacteristically reckless shot for 137 to end a second-wicket partnership of 215.
After winning the toss, Rahim chose to bowl first, but it turned out to be the wrong decision as the South African batsmen gave a masterclass to take a sizeable early advantage in the first Test in Potchefstroom. Kagiso Rabada made an early inroad while Morne Morkel followed up.
"I've never really looked at the game from a selfish perspective", Markram told reporters.
The pitch played easily all day, although the dry nature of the surface was shown by some balls which kept low. Dean Elgar became the tenth and first from South Africa to enter the exclusive club. Hopefully on the second day we can come back and try to contain them.
However, Tamim Iqbal finally walked out to bat at 5 and did the most hard job by weathering the storm in the final few minutes of the day.
Spinner Mehidy Hasan Miraz, brought on early as first change, conceded 101 runs in his 36 overs. Three part-time spinners shared another eight overs. They both have reached the milestones in the same over (102nd).
Runs scored by South Africa's top three - Elgar 199, Markram 97 and Amla 137 - the second-highest total for any team in an innings with none of them going past 200. After Test wins at home over Australia and England, Bangladesh will look to upset the Proteas in South Africa. The skipper scored a 57-ball 44 with seven fours and a six but Bangladesh probably needed more than that and the 67-run third-wicket stand with Mominul. He eventually fell to Maharaj, caught off bat and pad at short leg. His opening partner, debutant Aiden Markram, had been run out 97 on the first day. At this stage Tamim joined hands with Mominul Haque.
The 22-year-old Markram appeared to be heading for a dream start to his test career before he was caught out of his crease, backing up too quickly as he attempted to help opening partner Dean Elgar to reach a century.
Markram, who said he was "more than happy with the 97", added the most important thing was that the team was in a good position.
Last year, Indian opener - KL Rahul also missed out on his first double century in Chepauk when he got out on 199.
FC Barcelona bars public from match amid Catalan vote chaos
Barca have long supported Catalonia's right for a vote on independence, without throwing their weight behind the yes or no camp. Gerard Pique was featured in the Barcelona team, having earlier tweeted a picture of himself at a polling station.