The 20-year-old Chechen immigrant accused of killing a teacher and injuring others while on France's terror watchlist last week swore allegiance to the Islamic State group moments before the attack, according to prosecutors in the European country.

French authorities had been watching him closely for weeks, they said, and even stopped him the day before the deadly attack in Arras, about 115 miles north of Paris. But he was released due to a lack of evidence.

Hours later, bystander video shows him struggling in a paved courtyard at the Lycee Gambetta High School. According to authorities, he killed a teacher there and "gravely" wounded at least two more people.

KNIFE-WIELDING ATTACKER SHOUTS ‘ALLAHU AKBAR’ AND KILLS TEACHER IN FRENCH SCHOOL AMID HAMAS-ISRAEL WAR: REPORT

Police later recovered a recording of the pledge on his phone, according to Jean-Francois Ricard, France's anti-terror prosecutor.

GRAPHIC VIDEO: Eyewitness video show 2 teachers trying to stop French school knife attack

In the video, he declared "his hatred for France, for the French, for democracy and the education he benefited from in our country," Ricard told reporters at a news briefing in Paris, according to The Associated Press.

The suspect, identified by authorities only as Mohammed M., previously attended the school.

ISRAELI PM'S OFFICE RELEASES GRAPHIC PHOTOS PURPORTING TO SHOW HAMAS ‘MURDERED AND BURNED’ BABIES

Forensic investigators in protective suits at the school crime scene

French police officers in front of the Gambetta High School in Arras, France, after a man armed with a knife killed a teacher and wounded another teacher and a security guard, Friday Oct. 13, 2023. (Ludovic Marin, Pool via AP)

His full name is Mohammed Mogouchkov, according to La Voix du Nord, a newspaper based in northern France.

Sliman Hamzi, a police officer identified as one of the first responders on scene, told The Associated Press he heard the suspect shout "Allahu Akbar!"

French President Emmanuel Macron said the attack exemplifies "the barbarism of Islamic terrorism."

"This teacher was cowardly and savagely assassinated," he said last week. "Our thoughts are with the teacher's family and the families of those… wounded."

Police escort students after France School Attack

Schoolchildren leave the area after a man armed with a knife killed a teacher and wounded two others at a high school in northern France, Friday, Oct. 13, 2023. (AP Photo/Michel Spingler)

The suspect and two family members, including a 16-year-old younger brother, have been charged with terrorism, according to Ricard.

One of the wounded was a school administrator who also attempted to intervene and suffered life-threatening injuries, Macron said. He praised the victims for their heroics.

French reports noted that the knife attack happened just shy of three years to the day of the beheading of another French teacher, Samuel Paty, who was also killed by a radicalized Chechen.

A ISIS soldier and flag

An Islamic State militant is seen holding the terror group's flag. (History/Universal Images Group via Getty Images)

CLICK HERE TO GET THE FOX NEWS APP 

French authorities said early on they suspected terror as a motive in the attack, which comes amid a raging conflict in Israel following an attack by Hamas terrorists based in the Gaza Strip. However, they said they have not found a direct link to the Israeli conflict.

France's interior ministry has ordered a country-wide ban on demonstrations in support of the Palestinians

The Islamic State group, which rose to prominence with horrific propaganda videos that showed graphic murders, "encourages sympathizers to carry out simple attacks wherever they are located," according to the FBI.

The State Department has designated the group and many of its regional chapters as a designated foreign terrorist organization.

The Associated Press contributed to this report.