The assailant, whose identity has not been established, was shot by police as they tried to arrest him and later died of his injuries, police said.
The attacker shouted “Allahu Akbar” (“God is greatest”) as police confronted him, a cry often heard in jihadist attacks, a police source said.
France has seen a wave of Islamist violence since the 2015 terror attacks on the satirical magazine Charlie Hebdo and a Jewish supermarket in the capital.
French anti-terror prosecutors said they were treating the assault as “a murder linked to a terrorist organisation”.
The attack happened on the outskirts of Paris at around 5:00 pm (1500 GMT) near the middle school where the teacher worked in Conflans Saint-Honorine, a northwestern suburb around 30 kilometres (20 miles) from the city centre.
The killing bore the hallmarks of “an Islamist terrorist attack”, Macron said as he visited the scene.
Visibly moved, the president said that “the entire nation” stood ready to defend teachers and that “obscurantism will not win”.
Four people, including a minor, have been arrested, a judicial source told AFP early Saturday. All were related to the assailant, the source added.
– ‘Super nice, super friendly’ –
The victim was a history teacher who recently showed cartoons of the Prophet Mohammed as part of a class discussion on freedom of expression, police said.
A parent of a pupil at the school said the teacher might have stirred “controversy” by asking Muslim pupils to leave the room before showing the cartoons.
“According to my son, he was super nice, super friendly, super kind,” the parent, Nordine Chaouadi, told AFP.
The teacher “simply said to the Muslim children: ‘Leave, I don’t want it to hurt your feelings.’ That’s what my son told me,” the parent said.
According to a judicial source, an identity card found on the assailant indicated he was born in Moscow in 2002, although investigators were waiting for formal identification.
Police said they were investigating a tweet posted from an account that showed a picture of the teacher’s head, and which has since been shut down.
It was unclear whether the message, which contained a threat against Macron — described as “the leader of the infidels” — had been posted by the attacker, they said.
– ‘Nothing ever happens here’ –
Residents in the usually calm neighbourhood said they were shocked while pupils from the school, some accompanied by their parents, gathered in the street checking their phones for updates.
“Nothing ever happens here,” said Mohand Amara, who lives nearby, as he walked his dog not far from the school.
I saw him (the teacher) today, he came to my class to see our teacher. It’s shocking that I won’t see him again,” said Tiago, a student in sixth grade.
“It makes me sad — decapitated, that’s shocking,” said 15-year-old Virginie, who used to be the murdered teacher’s student and said she had “good memories” of him.
Police had arrived at the scene after receiving a call about a suspicious individual loitering near the school, a police source said.
They discovered the dead man and soon spotted the suspect, armed with a blade, who threatened them as they tried to arrest him.
They opened fire and injured him severely. The man later died of his injuries, a judicial source said.
– ‘Abominable’ –
The scene was cordoned off and a bomb disposal unit dispatched because of the suspected presence of an explosive vest, according to police.
France’s parliament suspended Friday’s debate after news of the decapitation, with session president Hugues Renson, visibly moved, calling the attack “abominable”.
MPs stood as Renson said that “in the name of all of us, I want to honour the memory of the victim.”
The killing comes as security forces have been on high alert during the ongoing trial of suspected accomplices of the attackers in the January 2015 terror attacks in Paris, which also saw a policewoman gunned down in the street.
It also comes just days after a follower of the Islamic State group who attacked a police officer with a hammer outside the Notre-Dame cathedral in Paris was sentenced to 28 years in jail.
And last month, charges were brought against a 25-year old Pakistani man after he wounded two people with a meat cleaver to avenge the publication of caricatures of the Prophet Mohammed by Charlie Hebdo, which purportedly prompted the 2015 killings.
Seventeen people were killed in the three-day spree that heralded a wave of Islamist violence in France that has so far claimed more than 250 lives.
In a tweet, Charlie Hebdo expressed its “sense of horror and revolt” at Friday’s attack.
This story has been published from a wire agency feed without modifications to the text. Only the headline has been changed.