The two Palestinian terrorists who carried out a lethal shooting at a central Tel Aviv restaurant last month had been “inspired” by the Islamic State but were not formally involved with the organization, according to an indictment filed Monday.

On June 8, cousins Muhammad and Khalid Muhamra opened fire in the Sarona Market entertainment area in the heart of Tel Aviv, killing Ido Ben Ari, Ilana Naveh, Michael Feige and Mila Mishayev, and wounding over a dozen others. They fled the scene but were captured alive by private security guards and police a short time later.

The Muhamra cousins had no escape plan for their attack, a spokesperson for the Shin Bet security agency told The Times of Israel.

“They trusted in Allah,” the official said.

The two Palestinian men, along with a third, Younis Ayash Musa Zayn, who had assisted and planned to join them, were charged with murder in a Tel Aviv District Court on Monday for the devastating attack.

Khalid Muhamra, left, Younis Ayash Musa Zayn, center, and Muhammad Muhamra, right, sit behind a glass window during their indictment in a Tel Aviv District Court on July 4, 2016. The three Palestinian men have been charged with murder in connection with the terror attack at the Sarona Market in central Tel Aviv in which four Israelis were killed. (Flash90)

Khalid Muhamra, left, Younis Ayash Musa Zayn, center, and Muhammad Muhamra, right, sit behind a glass window during their indictment in a Tel Aviv District Court on July 4, 2016. The three Palestinian men have been charged with murder in connection with the terror attack at the Sarona Market in central Tel Aviv in which four Israelis were killed. (Flash90)

Zayn did not take part in the attack for “technical reasons,” the Shin Bet security service said, but he had been involved in its conception and had purchased the guns used from a local manufacturer.

During their interrogations, the trio told investigators they had been planning the terror attack for approximately six months. They originally intended to carry out the shooting on a passenger train, but later changed their minds because of the difficulty in sneaking guns past security at the stations, according to the Shin Bet.

Israeli security forces at the scene of a deadly shooting attack at the Sarona Market shopping center in Tel Aviv, June 8, 2016. (Gili Yaari/Flash90)

Israeli security forces at the scene of a deadly shooting attack at the Sarona Market shopping center in Tel Aviv, June 8, 2016. (Gili Yaari/Flash90)

The decision to attack the Max Brenner restaurant in Sarona was “random and decided on the day of the attack,” the Shin Bet said in a statement.

The three young men, all in their early 20s, were residents of the Palestinian village of Yatta, outside of Hebron.

Khalid Muhamra (left) and Muhammad Muhamra (right), two Palestinian cousins from the West Bank village of Yatta who carried out the terror attack at the Sarona Market in central Tel Aviv in which four Israelis were killed. (Courtesy)

Khalid Muhamra (left) and Muhammad Muhamra (right), two Palestinian cousins from the West Bank village of Yatta who carried out the terror attack at the Sarona Market in central Tel Aviv in which four Israelis were killed. (Courtesy)

According to investigators, Muhammad Muhamra was a supporter of the Islamic State, having been exposed to its online propaganda. He had been living and studying in Jordan, but returned to Yatta in Jauary 2016, around the time he and his cousin decided to carry out the attack.

Though he was an Islamic State supporter, the Shin Bet stressed that there were no indications that the three had been “formally drafted into the organization” or that they received “assistance or instruction of any kind” from the terrorist group.

File. A Carl Gustav-style submachine gun used in a terror attack at the Damascus Gate outside of Jerusalem's Old City on February 3, 2016. (Israel Police)

File. A Carl Gustav-style submachine gun used in a terror attack at the Damascus Gate outside of Jerusalem’s Old City on February 3, 2016. (Israel Police)

The attack was carried out with improvised Carl Gustav-style submachine guns, known as Carlos, which have been used in a number of attacks during the ongoing terror wave. The simple, homemade submachine guns lack accuracy and range, but are well-suited for mayhem as they are generally fully automatic.

They were purchased from a gun manufacturer in Yatta, who has been arrested along with nine other local residents believed to have been involved in the attack in some way, the Shin Bet said.

“The grave terror attack in Tel Aviv demonstrates the considerable danger that can be seen in local terrorist initiatives, who make use of the accessibility to large amounts of standard and improvised weapons,” the Shin Bet said.

In addition to the threat of locally produced guns, the security service stressed the danger of the ease with which West Bank Palestinians can sneak into Israeli territory.

According to a joint investigation by the Shin Bet, IDF and Border Police, the Muhamra cousins left Yatta and made their way to the Israeli town of Meitar through a wide gap in the security barrier.

Once on the Israeli side in Meitar, the cousins were assisted by a Palestinian man working illegally in Israel who drove them to the Bedouin town of Segev Shalom, southeast of Beersheba.

This is where, according to the investigation, they changed into the formal attire — suits and ties — they wore when they carried out the attack.

Immediately following the attack, it was believed that the cousins had chosen their outfits in order to look like ultra-Orthodox Jews. This was later discredited, and according to the indictment, the Muhamras wore suits and ties in order to “blend into Tel Aviv.”

The scene of the Sarona complex terror attack in Tel Aviv on June 8, 2016 (Judah Ari Gross/Times of Israel)

The scene of the Sarona complex terror attack in Tel Aviv on June 8, 2016 (Judah Ari Gross/Times of Israel)

Dressed and armed, they took a taxi from Segev Shalom to Beersheba and another cab to Tel Aviv’s Sarona Market where, after entering and ordering dessert at the Max Brenner cafe, they got up and fired their weapons at the Israeli customers around them, killing four and wounding 16.

A cab ride from Beersheba to Tel Aviv takes less than two hours and costs approximately NIS 400 (about $100)

According to Channel 2, the taxi driver who took them from Beersheba to Tel Aviv was picked up by police for questioning, and claimed he had no idea who they were and what they planned to do.

“This investigation proves the need for cracking down on drivers who transport Palestinians without legal work permits into Israel despite the security risk,” the Shin Bet said Monday.

Times of Israel staff contributed to this report.