Eric Bekoe's 33rd-minute penalty for Petrojet canceled out Mohamed Al-Etrawi's opener from another spot kick on the quarter hour mark.
Mozambique striker Danilho Daniel struck the winner for The Peasants eight minutes from time.
Both sides finished with ten men. Bekoe controversially received a straight red card while Mahallah's Abdul-Hamid Shabana was sent off for two bookings.
Petrojet, who were considered title contenders earlier in the season, remained third in the league table on 43 points, five behind leaders and holders Ahli, who have two games in hand.
With five matches remaining for Petrojet, it looks highly unlikely that they will cause an upset and win their first ever league title.
Mahalla, who ended a five-match winless run, moved into 12th place with 28 points, four above the relegation zone.
Al-Etrawi converted a penalty after 15 minutes to put the hosts in front after Petrojet keeper Ahmed Fawzi needlessly rushed out of his goal and brought down Shabana.
Mahalla were unlucky not to extend their advantage four minutes later when Shabana's close-range volley went just over the bar.
Petrojet's shaky defense was exposed on several occasions by Mahalla forwards, who lacked the cutting edge.
Mahalla were made to pay for their wastefulness when Bekoe was felled by an opponent inside the area as the referee instantly pointed to the spot.
The Ghanaian striker, who joined Petrojet in January, stepped up to score the equalizer and take his tally to four league goals.
But his celebrations did not last for long as he received his marching orders on 58 minutes for no apparent reason.
The referee seemingly adjudged him to have hit an opponent in an off-ball challenge but Television replays showed there was no contact between Bekoe and any Mahalla player.
Mahalla also had Shabana dismissed with ten minutes remaining. He picked up a second yellow card for diving as numbers were evened up.
But the hosts still managed to claim all three points when the unmarked Daniel latched onto a long ball and sent a delicate chip over Fawzi and into the net.