BEIRUT — For nearly seven years, residents of the Lebanese capital went about their daily lives unaware that 2,750 tons of a highly volatile explosive material were stored in the heart of their city like a ticking time bomb.

After that material erupted Tuesday, killing at least 135 people and injuring 4,000 others, a portrait is now emerging of the staggering malfeasance that allowed it to sit in a warehouse in Beirut’s port for so many years — and of the repeated warnings that were ignored for so long.

Legal documents, court correspondence and statements by public officials now trying to pass the buck shed light on the operations of the port, which has been dogged by allegations of widespread bribery and controlled in large measure by the militant Hezbollah group.

Arms experts say Tuesday’s blasts are consistent with the official Lebanese explanation that an explosion was triggered in a vast stockpile of ammonium nitrate, which is unstable at high temperatures and 40 percent as explosive as TNT. U.S. defense officials say the explosions appear to have been a calamitous accident.

“This is such huge negligence,” said Assaad Thebian, director of the Gherbal Initiative, which advocates for transparency in Lebanese institutions. “We always said corruption would kill us. Now look at what has happened: more than 100 dead and thousands injured.”

The story begins in 2013, when the 86-meter-long (282 feet) cargo ship MV Rhosus, carrying 2,750 tons of ammonium nitrate, often used in fertilizer, made an unscheduled stop in Beirut, according to legal documents and Lebanese officials. Flying the flag of Moldova, it had been sailing from Georgia to Mozambique.

A report in a legal shipping bulletin said the vessel had “technical problems” and after inspection by the port authority was forbidden from sailing onward.

“Owing to the risks associated with retaining the Ammonium Nitrate on board the vessel, the port authorities discharged the cargo onto the port’s warehouses,” lawyers acting on behalf of creditors wrote in 2015. “The vessel and cargo remain to date in port awaiting auctioning and/or proper disposal,” it added.

That never happened.

The creditors’ lawyers wrote that the vessel was abandoned by its owners, and the ship ran out of supplies. The crew was stranded on board due to immigration restrictions — “Crew kept hostages on a floating bomb,” read the headline of a 2014 report on maritime news site FleetMon — before a legal appeal let them go home.

Badri Daher, director general of Beirut Customs, said he wrote several letters to Lebanon’s “judge of urgent matters” asking for guidance on what to do with the ammonium nitrate.

One letter from 2017 urged that it be re-exported “immediately” or sold off. Daher wrote that “we have not received any answer from you yet” and warned of “the extreme danger posed by the storage of the goods in the warehouse under inappropriate weather.”

Daher said he did not raise the alarm publicly because he was not authorized to discuss the legal proceedings.

One port employee said that the presence of the ammonium nitrate was long known and feared by some workers. He questioned why U.N. maritime forces responsible for searching vessels had not intervened.

“Corruption at the port is a rule,” he said. He said that while Hezbollah doesn’t directly get involved with matters at the port, the group “has the upper hand.” But he added that it is not the only political group that benefits off the port. “I can say all of them,” he said.

There is no evidence linking the explosions and Hezbollah. But Western intelligence officials looking into the episode are likely to scrutinize the militant group’s well-documented use of the port for smuggling rockets and other weapons, current and former U.S. officials said. Also potentially relevant is Hezbollah’s long-standing interest in ammonium nitrate, which the group has previously sought to acquire for bombmaking, the officials said.

Weapons experts said it is unclear how the explosion was ignited or what had been stored near the ammonium nitrate and might have triggered it. Videos that show the fire before the main blast show a “popcorning” of small blasts, “which is what munitions do,” said Jeffrey Lewis, a nonproliferation expert at the Middlebury Institute of International Studies.

The Trump administration last year imposed sanctions against high-level Hezbollah officials specifically accused of using Beirut’s port for smuggling contraband, “including illegal drugs and weapons,” according to a Treasury Department statement. Among those penalized was Wafiq Safa, Hezbollah’s head of security, who U.S. officials say was charge of ensuring that banned items could pass through the port without scrutiny from customs officials.

Among the weapons entering the port have been precision-guided missiles intended for use against Israel, according to a report earlier this year by the Israel Defense Forces. Between 2016 and 2018, Hezbollah smuggled Iranian missile components as well complete missiles “by air, using civilian flights to Rafiq Hariri International Airport in Beirut, and by sea, via the Port of Beirut,” the report said.

The precise port terminals used by Hezbollah are not publicly known, but among Lebanese it is widely believed that Hezbollah, as the country’s dominant political force at present, has virtually free rein over border crossings, said Firas Maksad, an adjunct professor at George Washington University’s Institute for Middle East Studies.

“Hezbollah is known to exercise control or leverage over the airport and the port, for various reasons having to do with their activities,” Maksad said. “There’s a preexisting notion in the psyche of most Lebanese that these facilities are either dominated by Hezbollah directly or through various surrogates.”

While Hezbollah had no known role in bringing the ammonium nitrate to Beirut’s harbor, the group has long shown an interest in acquiring the chemical for use in a variety of terrorist plots. Last year, a U.S. federal court in New York sentenced convicted Hezbollah operative Ali Kourani to a 40-year prison term for seeking to acquire hundreds of pounds of ammonium nitrate — in the form of chemical ice packs — from a Chinese manufacturer. Ammonium nitrate was the explosive chosen for terrorist plots linked to Hezbollah in Britain, Cyprus, Germany and Bulgaria.

“It is a fact that they have particular interest in ammonium nitrate,” said Matthew Levitt, a former FBI counterterrorism analyst and Hezbollah expert.

But whether Hezbollah had ever sought to gain control of the stores of the chemical at the Beirut port — or played a role in preventing its removal from the harbor — is not publicly known.

Morris reported from Berlin. Haidamous and Warrick reported from Washington. Missy Ryan and Souad Mekhennet in Washington contributed to this report.