The terrorists who carried out attacks in the German cities of Ansbach and Wurzburg last month planned their attacks with the help of Saudi Arabian Daesh members, Der Spiegel reported.

Two terrorists who attacked the German cities of Ansbach and Wurzburg last month allegedly had contact with Saudi Arabian members of the Daesh terrorist group, Der Spiegel reported on Friday.

On July 18 17-year-old refugee Riaz Khan Ahmadzai, who claimed to be from Afghanistan, attacked train passengers in Wurzburg, Bavaria, with an axe and knife.

He seriously injured five people in the attack, during which he shouted "Allahu Akbar" several times. A police investigation revealed that Ahmadzai, who was shot dead by police, had been a follower of the Daesh terrorist group, and discovered a video in which he pledged allegiance to Daesh.

According to Der Spiegel, German police have discovered internet chat messages between Ahmadzai and a Saudi Daesh member.

The messages reveal the man's first suggestion to Ahmadzai, that he drive a car into a crowd of people.

This method of attack was used by Tunisian-born Mohamed Lahouaiej Bouhlel in Nice, France on July 14. He killed 84 people and injured hundreds more before he was shot by French police.

However, Ahmadzai said he couldn't carry out such an attack, because he did not have a driving license. Instead, he announced his plan to get on a train and attack the first passengers he saw.

Daesh claimed responsibility for Ahmadzai's attack, and published a video online which allegedly shows the teenager pledging to carry out a suicide attack in Germany on behalf of Daesh.

The video's publication led linguistic experts to doubt Ahmadzai's claim to be a refugee from Afghanistan, because in it he uses words and phrases found in the Pakistani, not Afghan, variant of Pashto.

On July 24 Mohammed Daleel, a 27-year-old asylum seeker from Syria, carried out a suicide bombing outside a music festival in Ansbach, Bavaria; he was refused entrance to the festival itself because he didn't have a ticket. The attack killed Daleel, and seriously injured 12 people.

Daesh claimed responsibility for the attack and also released a video purporting to show Daleel pledging allegiance to the group. Its al-Nabaa propaganda magazine said that Daleel, who arrived in Europe in April 2013, had fought for the terrorist group in Iraq and Syria and had spent three months making the bomb he used in the attack.

German authorities told the newspaper they believe Daleel's death on July 24 was unintentional, and he had intended to leave the rucksack containing the bomb somewhere within the festival crowd.

"Shortly before the attack his (Daesh) chat contact asked him to film the explosion and subsequent blaze, and send it to Daesh. However, it appears the bomb exploded prematurely, killing him and injuring 15 people," Der Spiegel reported.

The chat messages also reveal that Daleel intended to perpetrate more attacks, and to record a video for Daesh in which he admits his responsibility for the bombing. During their search of his refugee accommodation in Ansbach, investigators also found more material for making a bomb.