Lebanese security officials warned the prime minister and president last month that 2,750 tonnes of ammonium nitrate stored at Beirut's port could destroy the capital if it exploded, documents show.
Just over two weeks later, the industrial chemicals exploded in a blast that obliterated most of the port, killed at least 163 people, injured 6,000 more and destroyed about 6,000 buildings.
A security official said the warehouse fire began when workers who were fixing an entrance to it used a welder, sparks from which ignited fireworks stowed next to the ammonium nitrate.
The report by the General Directorate of State Security about events leading up to the explosion included a reference to a letter sent to President Michel Aoun and Prime Minister Hassan Diab on July 20.
While the contents of the letter were not in the report, seen by Reuters, a senior security official said it summed up the findings of a judicial investigation launched in January.
The investigation concluded that the chemicals must be secured immediately.
"There was a danger that this material, if stolen, could be used in a terrorist attack," said the official, who was involved in writing the letter.
"At the end of the investigation, Prosecutor General [Ghassan] Oweidat prepared a final report, which was sent to the authorities.
"I warned them that this could destroy Beirut if it exploded."
Mr Diab's office and that of Mr Aoun did not respond to requests for comment about the letter.
The prosecutor general did not respond to requests for comment.
'Do what is necessary'
The correspondence could fuel further criticism and public fury that the blast was the latest example of government negligence and corruption that has pushed Lebanon to economic collapse.
As protests over the blast raged in Lebanon on Monday, Mr Diab's government resigned, although it will remain as a caretaker administration until a new Cabinet is formed.
The rebuilding of Beirut is expected to cost up to $15 billion (Dh55.1bn) in a country already effectively bankrupt with total banking system losses exceeding $100bn.
Mr Aoun confirmed last week that he had been told about the material.
He said he had directed the secretary general of the supreme defence council, a group of Lebanon's security and military agencies chaired by him, to "do what is necessary".
"[The state security service] said it is dangerous. I am not responsible," Mr Aoun said.
"I don't know where it was put and I didn't know how dangerous it was. I have no authority to deal with the port directly.
"There is a hierarchy and all those who knew should have known their duties to do the necessary."
Many questions remain over why the shipment of ammonium nitrate docked in Beirut in late 2013.
Even more baffling is why such a huge stash of dangerous material, used in bombs and fertiliser, remained there for so long.
The letter followed a string of memos and letters sent to the country's courts over the previous six years by port, Customs and security officials.
They repeatedly urged judges to order the removal of the ammonium nitrate from its position so close to the city centre.
The General Directorate of State Security's report said many requests had been submitted, without giving an exact number.
It said the port's manifest department sent several written requests to the Customs directorate up until 2016, asking it to call on a judge to order that the material be re-exported immediately.
"But until now, no decision has been issued over this matter," the state security report said.
"After consulting one of our chemical specialists, the expert confirmed that this material is dangerous and is used to produce explosives."
The road to last week's tragedy began seven years ago, when the Rhosus, a Russian-chartered, Moldovan-flagged vessel carrying ammonium nitrate from Georgia to Mozambique, docked in Beirut.
There it hoped to take on extra cargo to raise the fees for passage through the Suez Canal, the ship's captain said.
Port authorities impounded the Rhosus on December 2013 under a judicial order due to outstanding debts owed to two companies that filed claims in Beirut courts, the state security report showed.
In May 2014, the ship was deemed unseaworthy and its cargo was unloaded in October 2014 and stored in what was known as Hangar 12.
The ship sank near the port's breakwater on February 18, 2018, the report showed.
Moldova lists the owner of the ship as Panama-based Briarwood Corp. Briarwood could not immediately be reached for comment.
In February 2015, Nadim Zwain, a judge from the Summary Affairs Court that deals with urgent issues, appointed an expert to inspect the cargo, the security report said.
It said the expert concluded that the material was hazardous and, through the port authorities, requested it be transferred to the army.
Lebanese army command rejected the request and recommended the chemicals be transferred or sold to the privately owned Lebanese Explosives Company, the report said.
It did not say why the army refused to accept the cargo. A security official said it was because the army did not need it.
The explosive company's management said it had not been interested in buying confiscated material and that it had its own suppliers and government import licences.
From then on, Customs and security officials wrote to judges about every six months asking for the removal of the material.
Some Customs and port officials have since been detained as part of the investigation into the blast.
'Bad storage and bad judgment'
In January 2020, a judge launched an official investigation after it was discovered that Hangar 12 was unguarded, had a hole in its southern wall and one of its doors was dislodged, meaning the hazardous material was at risk of being stolen.
In his final report after the investigation, Mr Oweidat "gave orders immediately" to ensure hangar doors and holes were repaired and security provided, another high-ranking security official said.
On June 4, based on those orders, state security instructed port authorities to provide guards at Hangar 12, appoint a director for the warehouse and secure all the doors and repair the hole.
The port authorities did not immediately respond to requests for comment.
The security official said the maintenance started and port authorities sent a team of Syrian workers, but there was no one supervising them when they entered to fix the holes.
During the work, sparks from the welding took hold and fire started to spread, the official said.
"Given that there were fireworks stored in the same hangar, after an hour a big fire was set off by the fireworks and that spread to the material that exploded when the temperature exceeded 210 degrees," the high-ranking security official said.
The official blamed the port authorities for not supervising the repair crew and for storing fireworks alongside a vast deposit of high explosives.
"Only because the hangar faces the sea, the impact of the explosion was reduced," he said. "Otherwise all of Beirut would have been destroyed.
"The issue is all about negligence, irresponsibility, bad storage and bad judgment."