The long fuse that led to the explosion of violence that killed the US ambassador to Libya, Chris Stevens, was lit last summer in the pleasant hills of southern California, where a man who claims to be an Israeli-American real estate developer, Sam Bacile, set about making a film.

The citrus groves and villas around Los Angeles are home not just to Hollywood but to a lucrative underside, a vast industry pumping out huge numbers of amateur, gonzo productions for internet distribution, most of them pornographic. But few have been intended to be as grotesquely offensive as Bacile's production, and none have had such explosive consequences.

By his own account, Bacile raised a budget of $5m (£3m) from 100 unnamed Jewish donors for The Innocence of Muslims, which he wrote and directed himself, with the aim of demonstrating his belief, as he described it to the Wall Street Journal, that "Islam is a cancer".

To that end, Bacile got his amateur cast to depict the prophet Muhammad as a feckless philanderer who approved of child abuse. It took three months, 59 actors and about 45 crew. The result was two hours of stumbling dialogue and wooden acting among flimsy sets, and a stream of gratuitous insults aimed at Muslims. It was screened in an almost empty cinema in Hollywood earlier this year.

In another age, that would probably have been the end of the story. But in the YouTube era, in which the voices of fanatics are amplified, it was a bomb primed for detonation, months later and thousands of miles away.

Bacile posted a 13-minute English-language trailer on YouTube in early July but it was only in the past week that it appears to have caught the attention of combatants in the online culture wars.

A Florida pastor, Terry Jones, who had triggered protests in the Islamic world by burning the Qur'an and with his campaign to stop the construction of a mosque at the site of the 9/11 attacks, promoted the film on his website and announced his intention to broadcast the trailer at his Gainesville church this week.

"It is an American production, not designed to attack Muslims but to show the destructive ideology of Islam," he said in a statement. "The movie further reveals in a satirical fashion the life of Muhammad."

The film clip was also spotted and promoted last week by Morris Sadik, an Egyptian Coptic Christian based in California who runs a small virulently Islamophobic group called the National American Coptic Assembly. It was later denounced by mainstream Copts in Egypt, but it was too late to stop it going viral.

At some point over the summer a version of the YouTube trailer surfaced with the dialogue dubbed in Egyptian Arabic – Bacile says he has no idea who did the translation but has claimed it sounded accurate – and the translated clip was picked up by a firebrand Cairo television host, Sheikh Khaled Abdallah, who has a record of focusing on perceived threats to Islam and amplifying them. He aired clips from the video on his television show on Saturday, and the same video clips were posted to YouTube on Monday.

As the Arab audience for the film grew exponentially, militant Islamists called for a mass protest at the US embassy in Cairo. The organisers told Associated Press that planning began last week when Sadik began promoting the trailers but the support for the demonstration snowballed after the Sheikh Abdallah programme on Saturday.

A crowd of some 2,000 is reported to have gathered outside the embassy walls in Cairo on Tuesday night, catching the local security services flat-flooted. Most of the diplomats and local staff had left early and a few dozen of the demonstrators were able to scale the wall, take down the stars and stripes and replace it with a black flag. The Egyptian police only managed to evict them from the compound by late evening.

By that time, however, the spark had jumped westwards to the Libyan city of Benghazi. According to al-Jazeera, an extremist militia called Ansar al-Sharia, one of many such armed groups staking out little fiefdoms in the aftermath of Muammar Gaddafi's fall, heard about the storming of the Cairo embassy and the American film.

According to al-Jazeera's correspondent in Benghazi, Suleiman Idrissi, "At about 11.30 pm a group of people calling themselves Islamic law [Sharia] supporters heard there would be an American movie insulting the prophet Muhammad. Once they heard this news they came out out of their military garrison, and went into the streets calling on people to go ahead and attack the American consulate in Benghazi."

Rocket-propelled grenades were reported to have been fired from a farm next door to the consulate, and film clips on al-Jazeera show men roaming through the ornate gardens amid vehicles, vegetation and buildings in flames. Ambassador Stevens, who was on a short visit to Benghazi, is reported to have died from smoke inhalation, along with an American computer expert at the consulate, Sean Smith, and two security guards.

Smith was an internet gaming enthusiast and was chatting online to another player at the time of the attack. According to the other player, who goes by the online handle of The_Mittani, Smith "said 'FUCK' and 'GUNFIRE' and then disconnected and never returned".

By Wednesday, Sam Bacile was in hiding. He spoke to Associated Press from an undisclosed location, saying he had not expected such a furious reaction. He said: "I feel sorry for the embassy. I am mad." But Bacile still insisted that the movie would help Israel by exposing what he described as Islam's flaws to the world.

"My plan is to make a series of 200 hours," he said.