Chilean Marcel Allende put the home team ahead within three minutes before a 50,000 crowd, which was silenced soon after when Mohamed Sherif equalised.
Goals from Themba Zwane and Teboho Mokoena gave Sundowns a 3-1 half-time advantage that was cut when South African Percy Tau netted for Ahly just past the hour mark.
Namibian Peter Shalulile then took the game away from the visitors, scoring twice in the closing stages of the Group B showdown.
Last Tuesday, runaway Group C leaders Raja Casablanca of Morocco became the first qualifiers for the knockout phase.
It was only the second time Ahly have conceded five goals since their 1976 debut in the premier African club competition — they suffered a 5-0 drubbing away to Sundowns four years ago.
While Sundowns can look forward to a seventh quarter-finals appearance in eight editions, record 10-time African champions Ahly are in deep trouble.
The club that featured in five of the last six Champions League finals must win away to Coton Sport of Cameroon on March 17 to have any hope of survival.
But if Al Hilal of Sudan beat 2016 champions Sundowns in Omdurman the following day, they will join the South Africans in the knockout phase.
With two rounds remaining, Sundowns have 10 points, Hilal nine, Ahly four and Coton are pointless. Group winners and runners-up advance to the quarter-finals.
– Effective counterattacks –
“We have to stay focused because there is a long way to go,” said Sundowns coach Rhulani Mokwena, a 36-year-old who never played top-level football.
“I am privileged to coach very good footballers. Credit must also go to the wonderful supporters who once again created an uncomfortable environment for our opponents.”
Swiss coach Marcel Koller said Sundowns deserved to win because his Ahly players were “really poor in the first half.
“We took risks after half-time in order to get back into the game and, when trailing 3-2, I thought we could at least draw. However, Sundowns then counterattacked very effectively.”
Elsewhere, defending champions Wydad Casablanca of Morocco took control of Group A thanks to a 2-0 away win over Petro Luanda, the Angolan club they beat in the semi-finals last season.
The two non-Moroccans in the Wydad starting line-up scored with Arsene Zola from the Democratic Republic of Congo striking on 59 minutes and Senegalese Bouly Sambou in added time.
Seeking a fourth Champions League title, Wydad have nine points, JS Kabylie of Algeria seven, Petro four and V Club from DR Congo three.
Kabylie edged V Club 2-1 in Algiers thanks a late Massinissa Nait goal after Marouf Tchakei had put the visitors ahead early in the second half direct from a 40-metre free-kick.
Two-time African champions Kabylie are set to secure a last-eight place despite lacking a regular scorer — their nine goals in Africa this season have come from nine players.
5️⃣ OF THE BEST! The Brazilians put on a masterclass this afternoon in front of a packed-out Loftus, putting them top of group B!🔥
Mamelodi Sundowns (3' Allende, 23' Zwane, 39' Mokoena, 72', 82' Shalulile) 5️⃣➖2️⃣ Al Ahly SC (12' Sherif, 61' Tau)#Sundowns #TotalEnergiesCAFCL pic.twitter.com/2LHvqR0bF6
— Mamelodi Sundowns FC (@Masandawana) March 11, 2023
© Agence France-Presse