A Tunisian man who killed three people in a church in France only recently arrived in Europe, officials say.
The suspect, 21, had an Italian Red Cross document, issued after he arrived on the Italian island of Lampedusa by migrant boat last month.
He was shot by police and is in a critical condition. One of the victims was "virtually beheaded", said the French chief anti-terrorism prosecutor.
President Emmanuel Macron said it was an "Islamist terrorist attack".
Mr Macron said the number of soldiers being deployed to protect public places - such as churches and schools - would rise from 3,000 to 7,000. Anti-terror prosecutors have opened an investigation, and France has raised its national security alert to the highest level.
In another development, a 47-year-old man believed to have been in contact with the attacker was detained by police late on Thursday, French media reported.
Thursday's stabbings at a church in the southern city of Nice have echoes of another attack earlier this month near a school north-west of Paris. Samuel Paty, a teacher, was beheaded days after showing controversial cartoons of the Prophet Muhammad to some of his pupils.
That murder has heightened tensions in France. President Macron's defence of the right to publish the cartoons and the government's attempts to crack down on radical Islam have angered Turkey and other Muslim-majority countries.
The suspect in the attack in Nice was heard repeatedly shouting "Allahu Akbar" (God is greatest) before being shot by police.
A Koran, two telephones and a 30cm (12-inch) knife were found on the attacker, said chief anti-terrorist prosecutor Jean-François Ricard.
"We also found a bag left by the attacker. Next to this bag were two knives that were not used in the attack," he added.
Police sources named the attacker as Brahim Aouissaoui.
Speaking after visiting Nice, Mr Macron said: "If we are attacked once again it is for the values which are ours: freedom, for the possibility on our soil to believe freely and not to give in to any spirit of terror.
"I say it with great clarity once again today: we won't surrender anything."
Who were the victims of the attack?
All three were attacked inside the basilica on Thursday morning before the first Mass of the day.
Two died inside the church, one of them a 60-year-old woman who was "virtually beheaded" close to the font. She has not been named.
French media have named one victim as 55-year-old Vincent Loquès, a devout Catholic who had reportedly worked at the basilica for more than 10 years.
Mr Loquès, a father of two loved by many of the church's regulars, was opening the building when the attacker slit his throat, police say.
Vincent Loques, 45, a father-of-two and sacristan of the Notre Dame basilica in Nice.— Latin Mass Society (@latinmassuk) October 29, 2020
The third victim was named by Brazilian media as Simone Barreto Silva, a 44-year-old mother of three born in Salvador on Brazil's north-eastern coast. She had lived in France for 30 years.
She fled to a nearby cafe with multiple stab wounds but died shortly afterwards. "Tell my children that I love them," she told those who tried to help her, according to French media.
It later emerged that a witness had managed to raise the alarm with a special protection system set up by the city.
Four police officers arrived at the scene at 08:57 local time (07:57 GMT) and the attacker was shot and detained shortly afterwards, the anti-terrorist prosecutor said.
Two other attacks took place on Thursday, one in France and one in Saudi Arabia.
A man was shot dead in Montfavet near the southern French city of Avignon after threatening police with a handgun.
A guard was attacked outside the French consulate in Jeddah in Saudi Arabia. A suspect was arrested and the guard taken to hospital.
Four years ago Nice was the scene of one of France's worst jihadist attacks, when a Tunisian drove a truck into crowds celebrating Bastille Day on 14 July, killing 86 people.
Governments around the world have condemned Thursday's attack, including France's European neighbours, the US, Turkey, Egypt, Qatar and Lebanon.
Disoriented and frightened
The terrorist threat level in France is as high now as it was in 2015-16, the terrible days of Charlie Hebdo, Bataclan, the Nice lorry-killer and the murder of Father Hamel in his church in Rouen. Things were bad enough then - and many more people died in those attacks. So why does this outbreak of Islamist violence feel somehow more scary?
One reason must be the symbolism of the Samuel Paty beheading. That a simple history teacher could be murdered - and not randomly but actually selected for murder - has been deeply unsettling for French people. Likewise the targeting today of Christian worshippers in Nice.
But it is also the context: the instant logic of action-response that followed President Macron's robust defence of secularism at Samuel Paty's memorial 10 days ago. All it took was a speech, then there were the threats, then there were the deaths.
With a new Covid lockdown providing an eerie backdrop to these events, small wonder the French are feeling disoriented and frightened.
A timeline of recent attacks in France
October 2020: French teacher Samuel Paty is beheaded outside a school in a suburb of Paris
September 2020: Two people are stabbed and seriously hurt in Paris near the former offices of Charlie Hebdo, where Islamist militants carried out a deadly attack in 2015
October 2019: Radicalised police computer operator Mickaël Harpon is shot dead after stabbing to death three officers and a civilian worker at Paris police headquarters
July 2016: Two attackers kill a priest, Jacques Hamel, and seriously wound another hostage after storming a church in a suburb of Rouen in northern France
July 2016: A gunman drives a large lorry into a crowd celebrating Bastille Day in Nice, killing 86 people in an attack claimed by the Islamic State (IS) group
November 2015: Gunmen and suicide bombers launch multiple co-ordinated attacks on the Bataclan concert hall, a major stadium, restaurants and bars in Paris, leaving 130 people dead and hundreds wounded
January 2015: Two Islamist militant gunmen force their way into Charlie Hebdo's offices and shoot dead 12 people
Are you in the area? Did you witness what happened? If it's safe to do so, please share your experiences by emailing email@example.com
Please include a contact number if you are willing to speak to a BBC journalist. You can also get in touch in the following ways: