BAGHDAD—Thanks to the worst recorded heat wave in Iraq’s history, now in its fourth week, Abu Mahdi may be this city’s happiest man.

From a hole-in-the-wall shop on Baghdad’s east side, Mr. Mahdi repairs air conditioners. His counsel is sought by the powerful and humble. His wallet is bulging. Some customers are so desperate, he says, “they come into my shop, get on their knees, kiss my hand and say, ‘Please come and help me.’ ”

People across the Middle East are suffering under this summer’s historic heat, which has seen temperatures climb above 120 degrees.

In Baghdad, a city of some seven million people, the torment is aggravated by Iraq’s decrepit electrical system, which cuts out frequently and without warning on a daily basis.

Lights and television screens go dark and the hum of air conditioners and soft whir of refrigerator fans suddenly stop. The heat quickly builds until a household or privately run neighborhood generator is switched on and power restored.