Protecting a slender 2-1 first-leg lead, Ahly were caught by surprise early on when Congolese midfielder Fabrice Ngoma headed Raja in front after some slack marking.
Ahly's Tunisian left-back Ali Maaloul then wasted a penalty before central defender Mohamed Abdel-Moneim put them ahead on aggregate with a timely equaliser on the stroke of halftime, thanks to a corner from Maaloul.
The visitors defended doggedly in the second half, restricting Raja to a few opportunities and silencing a sell-out crowd at the Mohammed V Stadium in Casablanca.
However, Ahly's ever-reliable keeper Mohamed El-Shennawi came to their rescue at the death, blocking a close-range effort from Mohamed Zrida, who scored Raja's solitary gal in the first leg.
Ten-time winners Ahly qualified for the semis for a record-extending 18th time as they set up a last-four clash with Algeria's ES Setif, who stunned Esperance with a 1-0 victory in Tunisia earlier in the day following a goalless draw in the first leg.
Ngoma sent the fans to raptures after just five minutes, capping a move he started following a mistake from Aliou Dieng.
The burly Malian midfielder gave away possession on the edge of the area and Ngoma pounced on the loose ball to feed Abdelilah Madkour on the right and sneak towards the six-yard box unopposed.
Madkour's cross found Ngoma at the far post to rise between three defenders and easily head home.
Ahly had two golden chances to level the score and go ahead on aggregate.
On six minutes, Dieng could have atoned for his earlier mistake but he sent a free header over the bar from a good scoring position.
Eight minutes later, Ahly were awarded a penalty after a VAR review, with Raja skipper Mohsine Moutaouali recklessly hauling down Hussein El-Shahat.
However, Raja keeper Anas Zniti, who also blocked a penalty in the first leg, dived to his right to keep out the low shot of spot-kick specialist Maaloul.
Abdel-Moneim, who was one of Egypt's standout performers in their run to the African Nations Cup final in February, eased Ahly's nerves when he beat his marker to Maaloul's in-swinging corner at the near post to head home one minute before haftime.
Ahly coach Pitso Mosimane played it safe after the break, with his team defending in numbers as Raja mounted an onslaught, launching numerous crosses from both flanks.
However, the hosts could only create two clear-cut chances, with substitute Zakaria Habti sending a curling shot just over the bar in the 83rd minute and Zrida missing a sitter in stoppage time.
Ahly's Percy Tau and substitute Ahmed Abdel-Kader also failed to kill off the game after being foiled in two one-on-one situations.
(For more sports news and updates, follow Ahram Online Sports on Twitter at @AO_Sports and on Facebook at AhramOnlineSports.)