Cook made 115 and Amla hit 109 in a South Africa total of 329 for five at the close of play.
The pair put on 202 for the second wicket before Amla’s dismissal sparked a collapse in which four wickets, including that of Cook, fell for 36 runs.
“It was a great comeback,” said England vice-captain Joe Root.
Temba Bavuma and Quinton de Kock restored South Africa’s advantage with an unbeaten sixth wicket stand of 56.
Cook, called up at the age of 33 when the South African selectors finally opted for a specialist opening batsman to partner Dean Elgar, was calm and organised from the start of his 218-ball innings during which he hit 14 boundaries.
Amla, four months younger than Cook but 91 matches richer in Test experience, was back to his fluent best as he reached his century off 131 deliveries with 18 fours.
He hit one more four before he was bowled off an inside edge by Ben Stokes.
Cook was on 97 when Amla was dismissed and was still two short of his century when AB de Villiers was caught at second slip off Stuart Broad for his second duck in three innings since being appointed captain.
Cook went to his century off 187 balls when he tucked Stokes through midwicket for two and added 15 more runs before edging a ball from Chris Woakes into his stumps.
JP Duminy followed soon afterwards when he missed a pull shot against Ali and was leg before wicket on 16.
In contrast to his father, Jimmy, who was dismissed first ball on his Test debut against India in 1992/93, Stephen Cook scored four off the first ball he faced, a leg side half volley from James Anderson.
That’s my boy
Jimmy Cook, who was in the crowd on Friday, had to wait until the age of 39 to make his official Test debut after being a prolific scorer for South Africa in 19 unofficial “rebel” Tests during South Africa’s political isolation, including a hundred on debut against an English team in 1981/82.
Cook was the sixth South African to make a hundred on debut and the 100th in all Test matches.
The opener was greeted with a hug by his father when he was finally dismissed.
“It was the first time I have spoken to him today,” said Stephen.
“He gave me a call last night and said, ‘my boy, if you just don’t get out to the first one you are already better than me?’. I was really glad for that first one off the pads.”
Cook said he owed much to his father.
“He threw balls and fed me bowling machines for many years growing up. It’s one for him as well.”
A freak catch by James Taylor at short leg was England’s only success before tea after South Africa won the toss and decided to bat.
Elgar and Cook put on 35 for the first wicket before Elgar was caught by Taylor off Moeen Ali for 20 when the off-spinner was brought into the attack in the 11th over.
Elgar went for a pull shot and Taylor took avoiding action but the ball lodged between his legs and he was able to grab hold of it before it touched the ground.
Amla was dropped on five when he edged Stokes low to first slip, where skipper Alastair Cook, possibly obscured by diving wicketkeeper Jonny Bairstow, put down the chance.
Cook had a life on 47 when Bairstow again dived in front of his captain Cook and spilled a difficult chance off Broad.
Cook, who had hit 35 first-class centuries including a South African record score of 390, was one of five changes from the South African side beaten by seven wickets in the third Test in Johannesburg last week.
He was picked ahead of Stiaan van Zyl and Duminy replaced Faf du Plessis, while off-spinner Dale Piedt and seamer Kyle Abbott came in for Chris Morris and Hardus Viljoen.
De Kock returned after injury to keep wicket in place of Dane Vilas.
Woakes replaced the injured Steven Finn in the only change in the England team.
England hold a winning 2-0 lead in the series.