American diplomats were warned of possible violent unrest in Benghazi three days before the killings of US Ambassador Christopher Stevens and three members of his team, Libyan security officials say.

The claim came as the country's interim President, Mohammed el-Megarif, said his government had information that the attack on the US consulate had been planned by an Islamist group with links to al-Qa'ida and with foreigners taking part.

However, the American ambassador to the UN, Susan Rice, insisted that the killings had resulted from a demonstration against a film about the Prophet Mohamed, replicating protests in Cairo, which had been "hijacked" and got out of control.

The Independent has reported diplomatic sources who said that the threat of an attack against US interests in the region was known to the US administration 48 hours before it took place. The alert was issued by the State Department's Bureau of Diplomatic Security, but not made public. A State Department spokesman maintained: "We are not aware of any actionable intelligence indicating that an attack on the US Mission in Benghazi was planned or imminent."

But President Megarif told the American station National Public Radio: "We firmly believe that this was a pre-calculated, pre-planned attack that was carried out specifically to attack the US Consulate. A few of those who joined in were foreigners who had entered Libya from different directions, some of them definitely from Mali and Algeria."

A senior official of the biggest militia in Benghazi, the February 17th Brigade, told CNN that he had warned US diplomats of a rapidly deteriorating security situation in Benghazi three days before the attack. "The situation is frightening, it scares us," he said he had stressed during the meeting. Mr Stevens had been back in Libya for only a short time before US security officials decided it would be safe to make the journey to Benghazi during the anniversary of the 9/11 attacks. The British consulate in the city was shut after an ambush of a convoy carrying Dominic Asquith, the UK ambassador, in which his bodyguard were injured. The UN and International Committee of the Red Cross offices had been bombed and there had been a spate of political assassinations.

However, Ms Rice denied the Benghazi attack was pre-planned. She said: "Our current best assessment... is that... it was a spontaneous – not a premeditated – response to what had transpired in Cairo. "A small number of people came to the consulate. It seems to have been hijacked by some individual clusters of extremists who came with heavier weapons... And it then evolved from there." Mr Stevens was separated from his protection team during the attack. He was found, it is thought unconscious, by locals who took him to hospital where, doctors said, he died from smoke inhalation.