The Cairo giants were two up within the first 11 minutes, thanks to a penalty from Mohamed Abou-Treika and a powerful drive from Flavio Amado.
Tarek Al-Sayed pulled one back and Ahed Abdul-Maguid converted a second-half penalty to level the score as Tersana looked determined to cause a huge upset.
Veteran midfielder Ahmed Hassan, who was to blame for Abdul-Maguid's goal, came to Ahli's rescue when he blasted in a superb shot from the edge of the area to give them all three points.
The victory will help Ahli put their stunning Champions League elimination behind them as they chase a fifth consecutive league title.
They moved into top spot on 57 points, ahead of second-placed Ismaili on goal difference with two matches to go.
A playoff match will determine the league winner if Ahli and Ismaili finish level on points.
Second-bottom Tersana, who are seven points adrift of safety, followed Olympic to the second division.
Makeshift Defense
Ahli boss Manuel Jose was forced to field a makeshift defense due to the injury of regular duo Shadi Mohamed and Wael Gomaa.
Natural right-back Ahmed Ali was handed a rare starting berth to play as a central defender along with Mohamed Samir and Ahmed Al-Sayed.
Ahli needed ten minutes to grab the lead amid enthusiastic support from the home crowd.
Mercurial midfielder Mohamed Barakat capitalized on a mis-hit clearance by Tersana midfielder Mohamed Al-Rayes to gather the ball inside the area.
Al-Rayes involuntary brought him down as the referee instantly pointed to the spot. Abou-Treika stepped up to convert the penalty and put Ahli ahead.
The Red Devils looked to have killed off the game just one minute later.
Abou-Treika controlled Hassan's pass inside the area with his back to goal and laid off the ball to Flavio, whose powerful right-footed shot left the keeper with no chance.
Tersana's veteran winger Al-Sayed gave the visitors a lifeline on 27 minutes when his low free-kick went through Ahli's poorly constructed wall and into the bottom corner.
Ahli's sluggish display allowed the Hammers to push forward and threaten Palestinian keeper Ramzi Saleh more than once.
Few minutes before the break, Saleh misjudged a cross at the far post but Ibrahim Al-Bahnasi's header hit the side netting.
Zero to Hero
Abou-Treika should have restored Ahli's two-goal cushion in the 52nd minute when he went one-on-one with Tersana keeper Ahmed Saad but his effort missed the target.
Ahli were made to pay for his miss one minute later when Hassan clumsily tugged Al-Sayed as Tersana were awarded a penalty.
Saleh dived the right way but couldn't block Abdul-Maguid's spot kick as Tersana made a surprising comeback.
Hassan atoned for his blunder to go from zero to hero and spare Ahli's blushes.
In the 59th minute, Flavio's clever dummy found the former Anderlecht man, whose thunderbolt went into the top corner of the net.