Record heat waves and crippling energy shortages across much of the Middle East are plunging homes and businesses from Lebanon to Iran into darkness and stirring unrest as poor families swelter while many of the rich stay cool with backup generators.

Power outages have pushed hospitals to a crisis point. Family businesses are struggling to survive. In some cities, the streetlights barely work.

Temperatures in several Middle Eastern countries this summer have topped 122 degrees Fahrenheit — 50 degrees Celsius — including in Iran, which hit 123.8, and Iraq, which nearly matched last year’s record of 125.2. Decades of neglect and underinvestment have left power grids unable to cope. Drought has crippled hydroelectric generation. Economic crises roiling several countries mean governments are now even struggling to purchase the fuel needed to generate power.

“It’s aggravated by climate change and increasing temperatures, but the roots of this are poor planning, weak governance and low investment in the power sector,” said Jessica Obeid, a nonresident scholar at the Washington-based Middle East Institute.

In Iran, the outages have sparked protests in several cities and prompted a rare apology this month from outgoing President Hassan Rouhani. As anger spreads, demonstrations have also erupted over water shortages in Khuzestan, a province in southwestern Iran. Amnesty International said in a report released Friday that security forces had responded to the protests with live ammunition and killed at least eight protesters and bystanders.

In Iraq’s oil-rich city of Basra, demonstrators have blocked highways and burned tires as they decried a lack of power and poor public services. Protesters have done the same in scattered demonstrations in Lebanon.

With government power grids faltering across the region, sites ranging from state ministries to family homes have turned to privately run backup generators, with an army of operators working in hot, dark trailers round-the-clock to keep them going.

On a recent day in Baghdad, one of those laborers sighed as he looked up at the hulking metal contraption he watches 12 hours a day, trying to stop it from overheating by repeatedly hosing it down.

“When the generator goes out, my phone rings so constantly that it’s hot to the touch,” said Mahmoud Ismail, 25. “People get desperate when the power goes out.”

These ubiquitous generators, powered by diesel fuel, pose risks of their own by belching toxic fumes, experts say, and customers are forced to pay exorbitant electricity bills to the unaccountable and often corrupt businessmen who own the machines.

As wealthy families across the region pay large sums for generators to power their air conditioning, the less affluent are spending increasing chunks of their income just to keep their lights on.