The French president urged the country to “stand all together as citizens” as he visited the scene in the town of Conflans-Saint-Honorine.
“One of our compatriots was murdered today because he was teaching pupils about freedom of expression, the freedom to believe or not believe,” Mr Macron said.
“Our compatriot was flagrantly attacked, was the victim of an Islamist terrorist attack… They won’t win… We will act. Firmly, And quickly. You can count on my determination.”
Minutes later he tweeted the short phrase “Ils ne passeront pas”, meaning: “They will not pass.”
Former president Francois Hollande tweeted: “With the appalling assassination of a teacher, the Republic and its school are once again the target of Islamist terrorism.
“More than ever, we must be united in the face of barbarism and obscurantism. My thoughts are with the family of the teacher and the whole educational community.”
The French anti-terrorism prosecutor’s office said it has opened an investigation “concerning murder with a suspected terrorist motive”.
According to police, the suspect attacked the victim in the street outside the school at around 5pm on Friday.
The suspect, who was armed with a pellet gun and a knife, was shot dead around 600 metres away in the nearby town of Eragny.
Neither the victim nor the suspect have been officially identified. French media reported that the suspect was an 18-year-old Chechen, born in Moscow.
The attack came as Mr Macron’s government pushed for a new law against what he calls domestic “separatism” by Islamic radicals accused of indoctrinating vulnerable people through home schools and extremist preaching.
France has the largest Muslim population in Western Europe with up to 5 million members.
Additional reporting by agencies.