A locally built Iranian passenger plane crashed shortly after takeoff in Tehran on Sunday, killing 39 people and reviving questions about the safety of a cash-strapped aviation sector left hobbled by international sanctions.

President Hassan Rouhani offered his condolences to victims’ families and quickly ordered an investigation into the crash. Similar planes operated by Iranian carriers will be grounded until the probe is complete, he directed.

The plane was based on a relatively obscure Ukrainian design that has been involved in previous Iranian air disasters.

The Sepahan Air regional airliner, bound for the eastern town of Tabas, went down in a residential area shortly after takeoff at 9:20 a.m. from Tehran’s Mehrabad airport.

State TV said the plane’s tail struck the cables of an electricity tower before it hit the ground and burst into flames. The official IRNA news agency said the plane suffered an engine failure. Whatever the ultimate cause, quick thinking by the pilot may have saved some lives.

“We should be thankful to God that the pilot did all he could to steer the plane away from residential buildings and fortunately did not crash into them. Otherwise, we would have been dealing with a much worse crisis,” said Jalal Maleki, spokesman of Tehran’s Fire Department.

Known as an IrAn-140 or Iran-140, the twin-engine turboprop is a version of the Antonov An-140 regional plane and is assembled under license in Iran. It can carry up to 52 passengers.

Iranian airlines, including those run by the state, are chronically strapped for cash, rely on aging planes and have a spotty maintenance record.

While some operate Boeing and Airbus models, spare parts for Western-made planes are often hard to come by — largely because of sanctions aimed at Iran’s nuclear program.

Those difficulties have left Iranian airlines increasingly reliant on planes developed by the Soviet Union and its successor states, though parts for aging Soviet-era planes can also be tough to get.

At the crash site, members of the elite Revolutionary Guard worked to secure the scene from onlookers while security and rescue personnel combed the wreckage. The plane’s mangled but largely intact tail section was torn from the fuselage and came to rest on a nearby road.

State TV said the bodies of some of the victims were so badly burned that they could not be identified. They will be handed over to relatives after DNA tests are carried out to determine their identities, it said.

The country’s creaking airline industry has been hit by a series of deadly crashes.

In March of this year, a small plane belonging to the State Aviation Organization crashed while on a test flight near the tourist resort of Kish Island, killing all four crew members.

The last major airliner crash in Iran happened in January 2011, when an Iran Air Boeing 727 broke to pieces on impact while trying an emergency landing in a snowstorm in northwestern Iran, killing at least 77 people.