South Africa, bowled out for 194 in the first innings, were 37 for one at the close in reply to England's 316. James Anderson trapped skipper Graeme Smith lbw for nought in the first over. Neil McKenzie was nine not out at stumps and Hashim Amla unbeaten on 26.
The swashbuckling Pietersen, five days into the skipper's job, rode his luck and was dropped twice but also hit 15 fours before falling for 100.
He was removed by paceman Makhaya Ntini, who finished with five for 94.
South Africa fought back after tea, capturing six wickets for 84 runs despite a lively cameo from recalled Steve Harmison.
The Durham paceman followed up Thursday's fine bowling display with 49, his highest test score, and shared a 53-run ninth-wicket partnership with Anderson (13).
A spell of three for 15 from Jacques Kallis after tea removed Andrew Flintoff (nine), Paul Collingwood (61) and Tim Ambrose (four).
Earlier, South African-born Pietersen, who took over as skipper from Michael Vaughan after the visitors had clinched the series at Edgbaston, came to the crease to warm applause in the first over of the day after Ntini had Ian Bell caught at slip for 24.
Pietersen put on 60 with Alastair Cook before the opener was caught behind just before lunch for 39.
Ntini, who took the wicket of Andrew Strauss on Thursday, had little luck after lunch.
He chased a Pietersen miscue ahead of team mate Paul Harris, who was closer to the ball, but failed to hold on at deep square leg with the batsman on 61.
After a brief break for bad light, Pietersen again sent a ball high to the boundary and Ntini put down a difficult running chance over his shoulder.
Otherwise Pietersen, the third England captain to score a century in his first innings in the job after Archie MacLaren in 1897 and Allan Lamb in 1990, played a measured knock, punishing loose deliveries and stroking the ball all round the ground.
He was desperate to salvage pride from the dead rubber and reached his century after a nervous few overs in the 90s, with a four to the mid-wicket boundary.
Pietersen raised his arms and danced across the pitch in celebration, waving his bat at the pavilion. Two balls later he was back there with his team mates, however, after playing at a wide ball and nicking a catch to Kallis at slip.
He had put on 108 for the fourth wicket with Collingwood.
Flintoff, plagued by injury this year, came to the crease after Pietersen departed and hit a straight six down the ground but was then caught behind in the first over after tea.
Wicketkeeper Ambrose lasted only 14 minutes before sending a catch to Smith and Collingwood was caught and bowled by Kallis when the ball ballooned off the shoulder of his bat.
Ntini took his fifth wicket, completing his 18th five-wicket haul in tests, when Stuart Broad (one) offered a catch to McKenzie.
It was Harmison who put England in pole position late in the day, flaying the bowling with his unorthodox attacking shots.
He missed out on his half century when Anderson was out lbw padding up to a straight ball and last man Monty Panesar was run out attempting to get Harmison his 50.