Steve Bruce's side turned in a poor first-half display at the KC Stadium but broke the deadlock two minutes after the restart when Egyptian forward Gedo, a deadline-day signing, scored having been summoned from the bench at the interval.
That looked like being enough for three important points until Northern Ireland international Jamie Ward levelled for Derby in the 84th minute.
Gedo's compatriot Elmohamady then won it for the hosts just three minutes later, before the Rams saw Gareth Roberts sent off in the closing seconds.
Middlesbrough's play-off hopes received a shot in the arm as they broke a sequence of five successive defeats with a 1-0 home win against Leeds.
Curtis Main was the match-winner, netting nine minutes from time to leave his side four points clear in sixth place, though he was sent off shortly afterwards.
Boro's nearest challengers are Brighton, who drew 1-1 with visiting Blackburn.
Scott Dann gave Rovers a 24th-minute lead but Vicente claimed a point for the Seagulls from the penalty spot after Danny Murphy transgressed.
- Sports & Recreation