BAGHDAD — 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.

In Lebanon, people have long been accustomed to daily three-hour electricity cuts — the country has not had a 24-hour supply since the civil war ended in 1990 — and there was even a phone app notifying residents when the cuts would take place.

But Lebanon’s dramatic economic collapse in recent months has left the government without enough fuel to provide electricity for most of the day. Now the entire country runs on generators, and the state-run electricity company’s website, which used to show tallies of electricity hours, is down.

Power shortages have also hit cities across Iraq after it fell behind on payments to neighboring Iran for the large quantity of cross-border electricity it traditionally provided, causing Iran to cut off the supply. A review by the Associated Press in June showed that the amount of electricity flowing from four lines that cross from Iran into Iraq had dropped to zero, at least temporarily.

In Baghdad, business owners said outages are prompting long nights of desperation as they stay up finding ways to reconfigure their budgets to pay for enough generator power to keep the electricity flowing. Prices vary, but businesses can pay thousands of dollars to keep the lights on.

“If the power goes out, we lose everything, so we have to keep these lights on,” said Abdulkarim al-Zoubi, standing in his family-run juice shop. “The fruits would go rotten, people would get sick.” His shoulders sank as he leaned across the counter.

“Without electricity, this place dies.”

Next door in Syria, fuel shortages afflict most of the country. Some Syrians note that power cuts seem less frequent in the capital, Damascus, and its surroundings, as well in coastal areas heavily populated by President Bashar al-Assad’s supporters, while the rest of the country suffers. In areas north of Damascus, residents have complained online for months that cuts have reached 20 hours a day. In Aleppo, the pro-government newspaper al-Watan reported, cuts sometimes last for eight hours at a time, with 1½ hours of electricity in between.

Officials across the region are beseeching citizens to reduce consumption, especially between midday and sunset. In Iran, authorities published schedules for the blackouts, although some said electricity companies never adhered to the schedules.

“What really happens has little to do with their predictions,” said Alireza, 40, who owns a small catering company. If he receives a birthday cake order for 6 p.m., he tries to start work early in the morning to finish before the scheduled afternoon power cut. “But suddenly the outage starts at 8 a.m.,” he said.

Florists, restaurant owners and others are also facing losses. “I saw butchers bringing meat out of their shops and cutting it on the pavement, because it spoils even more quickly inside,” said Alireza, who spoke on the condition that his last name be withheld to avoid attracting scrutiny from Iran’s authorities.

Earlier this month, a 62-year-old Iranian man who had been suffering from a lung-related illness requiring a ventilator died during a seven-hour electricity outage in the suburbs of Tehran, his daughter said in an interview. By the time a doctor arrived, it was too late, said the daughter, who spoke on the condition of anonymity for fear of government retaliation.

The challenge for the region’s hospitals, already stretched thin by the coronavirus epidemic, is especially daunting.

In a cellphone video that went viral this month, an ICU doctor in Tehran claimed that patients in a critical care unit had died when power was cut to ventilators as a result of the outages. “We have encountered such scenes many times,” the doctor, Mohamadreza Hashemian, wrote in a social media post that was quoted by Iranian news outlets.

Rouhani has called the claims that patients were dying an “utter lie” and said all hospitals had emergency generators.

With protests spreading, Rouhani apologized this month for the unpredictability of electricity cuts. “Power outages are temporary and have a history in the past and can be managed, but what can be more annoying than blackouts is a sudden power outage without a schedule,” he said.

Researchers say the region’s power shortages have been exacerbated by rampant corruption. “The power sector is usually a hub for it,” said Obeid, of the Middle East Institute. “There are just so many places along the power supply chain for corruption schemes, and without accountability, power gets lost and citizens can’t pinpoint where.”

A spate of explosive attacks on Iraqi government electricity pylons last month, for instance, were partly the doing of private business interests that wanted to ensure their generators were used instead, according to several politicians and businessmen.

In a photograph from one of the Basra protests, a teenager’s eyes bored into the camera as he held his sign aloft. “Corruption is killing me,” it said.

The proliferation of generators may be doing the same, health experts say.

A team of chemists at the American University in Beirut, led by Najat Saliba, estimated this month that Lebanon’s nearly 24-hour reliance on generators is poisoning the air eight times as fast as when Beirut was operating generators on average only several hours a day.

This could result in an additional 550 cancer cases a year, they said, as well as 3,000 new diagnoses of cardiovascular disease. “This would result in overwhelming health consequences and a heavy associated bill amounting to $8 million per year,” they wrote in Lebanon’s an-Nahar newspaper.

The health consequences of the power cuts could extend much further. In Iran, Mohamad Mohebi, 40, an electrical engineer who works as a consultant to Iran’s energy industry, described the impact of the cuts on people’s health and mental wellness as “devastating.”

The brutal heat is punishing and has already been linked to the death of small children in Lebanon and Iran.

“The heat is so bad that it hurts you. It’s hard to even describe to someone who hasn’t experienced it,” said Tahsin Mohamed, sitting in his home in the southern Iraqi town of Majer on a recent day. He rolled up his long, black djellaba shirt to reveal a burn scar etched on his shin.

“Imagine,” he said. “The sun did that to me.”

Fahim reported from Istanbul and Dadouch from Beirut. Mustafa Salim in Baghdad and Nader Durgham in Beirut contributed to this report.