The Strasbourg gunman yelled "Allahu Akbar" ("God is greatest" in Arabic) as he opened fire on people at a Christmas market, France's anti-terror prosecutor has told reporters.
Rémy Heitz said two people were killed and one left brain-dead in Tuesday's attack in the eastern French city.
Twelve were wounded, six seriously.
The main suspect, named by local media as Chérif Chekatt, is known to authorities as someone who was radicalised in prison.
The 29-year-old was armed with a gun and a knife and escaped the area in a taxi, Heitz said.
The attacker boasted to the driver - who has spoken to police - that he had killed 10 people, and said he had been injured in a firefight with soldiers.
Four people connected to the suspect had been detained overnight in Strasbourg, Heitz added. Sources close to the investigation quoted by Reuters news agency said they were the suspect's mother, father and two brothers.
Hundreds of officers are currently involved in the search for the gunman.
France's Deputy Interior Minister Laurent Nuñez earlier acknowledged he might no longer be in France. Strasbourg is close to the border with Germany.
Interior Minister Christophe Castaner said the country had moved to the highest level of alert, expanding police powers and increasing vigilance.
He added that border controls had been strengthened and security at all Christmas markets would be stepped up.
The mayor of Strasbourg, Roland Ries, has said the Christmas market will be closed on Wednesday and Thursday, with flags lowered to half-mast at the local town hall.
The attack unfolded at around 20:00 local time (19:00 GMT) on Tuesday close to Strasbourg's famed Christmas market near one of the central squares, Place Kléber, which attracts thousands of visitors at this time of year.
A woman called Audrey told France's BFM TV how she came face to face with the killer after watching him shoot a man in the head.
The gunman then opened fire for a second time, and another man fell to ground.
Her friends began to run to safety, but Audrey was frozen to the spot. The gunman turned, and faced her - but then he too ran.
"Why didn't he shoot at me?" she told the TV channel. "I don't know. I think I was extremely lucky. As everyone was screaming he fled."
According to Heitz, as he fled he came into contact with four soldiers. He began firing at them and they fired back, apparently hitting him in the arm.
He managed to reach a taxi which drove him away from the scene and dropped him in the vicinity of the police station in Neudorf, the area where he lives which sits on the border between Germany and France.
When he got out the vehicle, he fired at police officers.
What do we know about the gunman?
According to police - who refer to him as Chérif C - the gunman was born in Strasbourg and was already known to the security services as a possible Islamist terrorist threat.
He was the subject of a "fiche S", a watchlist of people who represent a potential threat to national security.
He has 27 convictions for crimes including robbery spanning France, Germany and Switzerland, and has spent considerable time in prison as a result.
Police were seeking him on Tuesday morning in connection with another case, but did not find him at home.
Nuñez said his crimes had never before been terrorism-related. But, he added, it was during one period in prison that he was indentified as having become radicalised.
"The fact he was a 'fiche S' did not pre-judge his level of dangerousness," Nuñez told France Inter.
A search of his home revealed a grenade, a rifle, four knives - two of which were hunting knives - and ammunition.
'Weary and deflated'
Strasbourg's famous Christmas market is now a gloomy place.
The lines of wooden huts are all shuttered. The owner of one told us how he had to flee when he heard the gunshots and take shelter in a local bar. "We're all shaken up," he said.
At this time of year, the place should be thronged with people who come from far and wide to sightsee and shop, buying everything from hot sausages to souvenirs. Now there's a weary, deflated feeling. Police stand guard at cordoned off alleyways.
"Everyone was shouting, everyone was running, running, afraid," said one eyewitness who'd seen the gunman shooting randomly.
Strasbourg has been a target for failed terror attacks before. But now it's happened, people here are hurt and outraged. As one said: "It's shameful."
What about the victims?
Anupong Suebsamarn, 45, a tourist from Thailand, has been named by Thai media as one of the dead. He is believed to have been on holiday with his wife.
The Italian foreign ministry has said one of the injured is an Italian journalist who was covering the European parliament, but declined to confirm media reports that he was in a serious condition.
One soldier was slightly injured by a ricocheting bullet during an exchange of fire with the gunman.
Why is Strasbourg a target?
Strasbourg has been the target of jihadist plots in the past.
Not only does it have one of France's oldest Christmas markets, but it is the official seat of the European Parliament. That parliament was in session at the time of Tuesday evening's attack.
In 2000, the Christmas market was at the centre of a failed al-Qaeda plot. Ten Islamist militants were jailed four years later for their part in the planned New Year's Eve attack.
However, MEPs were determined to carry on the morning after the attack, with German MEP Jo Leinen posting a picture of singing and Christmas lights in the European Parliament.