At least eight people were injured in France on Thursday when a heavily armed student who had watched videos of American-style mass shootings shot the headmaster — sparking a stampede and prompting a terror warning, police said.

The shooting rattled nerves in a country still reeling from attacks by ISIS jihadists – but officials in the quiet town of Grasse near the French Riviera said the school shooting was not terror related.

Kylian Barbey, 17, changed his Facebook profile picture to a gun-wielding skeleton from a violent video game before launching his attack at the Alexis de Tocqueville high school, The Sun of the UK reported.

The lone-wolf assailant – the son of a far-right politician — was armed with a shotgun, two handguns and two fake grenades, officials said.

The shooting occurred shortly after a female employee of the International Monetary Fund was injured in the face and arms when a letter bomb sent to the world lender’s Paris office blew up as she opened it, Reuters reported.

In the school attack, headmaster Herve Pizzinat and two students, Julie, 16, and Akram, 17, suffered non-life-threatening injures The Sun reported. Five others were hurt as they fled the mayhem.

French Education Minister Najat Vallaud-Belkacem described the attack as an “act of madness” carried out by someone fascinated with weapons. Barbey also was described as a “lonely Satanist” obsessed with heavy metal.

His internet accounts revealed he had been watching videos of mass attacks, including the shooting at Columbine High School in Colorado in 1999 that killed 13 people, Le Monde reported, citing a police source.

The last photo posted on the Facebook page belonging to “Killian” is an image of a person holding two guns and wearing a trench coat, similar to the outfits associated with the Columbine shooters. He also posted a video of himself wearing a skull mask and holding a gun to his head.

“He was gentle and low-key key, not a nasty guy,” Achraf, a student, told BFM-TV.

Authorities said there was no immediate motive for the attack, according to a spokesman for the French Interior Ministry.

Another student described the chaos when the shooting erupted.

“I was sitting down finishing my lunch. I heard a big explosion, then two others,” Benjamin told newspaper Nice Matin. “I turned and saw someone in the schoolyard with a pump-action shotgun, firing. He fired through windows into the classrooms overlooking the yard. When I saw that, I ran away.”

The teen’s father, Franck Barbey, is an elected municipal councilman for the extreme-right Rally for France party, which fights globalization, European federalism and immigration, news.com.au reported.

“Heartfelt support for the director, the teachers, the staff, the pupils and the parents of pupils,” the father tweeted.

The terror alert came in a system implemented by the government after the deadly November 2015 attacks in Paris. France also has been on heightened alert after an attack last year in Nice — 25 miles from Grasse — in which 86 people were killed.

Prime Minister Bernard Cazeneuve cut short a trip to the northern Somme area because of the shooting, as well as a letter bomb explosion at the IMF offices near the Arc de Triomph in Paris.

“It was something that was fairly homemade,” police Chief Michel Cadot told reporters about the letter bomb.

Cadot said there had been some recent telephone threats but it was unclear if these were linked to the incident at the IMF’s offices.

A police source said the woman who opened the letter suffered non-life-threatening burns on her face and arms.

IMF chief Christine Lagarde condemned the explosion as “a cowardly act of violence.”

“I … reaffirm the IMF’s resolve to continue our work in line with our mandate. We are working closely with the French authorities to investigate this incident and ensure the safety of our staff,” she said.

The IMF has been involved in discussions between Greece and its international creditors on disbursing new loans to Athens under a bailout program.

France is in the middle of a presidential campaign ahead of elections in six weeks.

With Post Wires