A suspect was arrested after the Thursday morning attack at the Notre Dame Church in Nice and taken to a nearby hospital after being injured as he was detained.
He was believed to be acting alone and police are not searching for other attackers, an official said.
The anti-terrorism prosecutor's office said an investigation was opened into an attack with a terrorist connection.
Images on French media showed the neighbourhood locked down and surrounded by police and emergency vehicles.
Sounds of explosions could be heard as sappers exploded suspicious objects.
The exact motive of the attack was unclear but comes as France is under alert for Islamic extremist acts amid tensions over caricatures of the Muslim Prophet Mohammed published by satirical French weekly Charlie Hebdo, and after two other recent attacks in France with links to the cartoons.
Less than two weeks ago, an attacker decapitated a French middle school teacher who showed caricatures of the Prophet Muhammed for a class on free speech. Those caricatures were published by Charlie Hebdo and cited by the men who gunned down the newspaper's editorial meeting in 2015.
In September, a man who had sought asylum in France attacked bystanders outside Charlie Hebdo's former offices with a butcher knife.
The lower house of parliament suspended a debate on new virus restrictions and held a moment of silence Thursday for the victims.
The prime minister rushed from the hall to head to a crisis centre overseeing the aftermath of the attack.
Nice's mayor Christian Estrosi said the attacker shouted "Allahu akbar!" repeatedly as police apprehended him and that "the meaning of his gesture left no doubt".
Speaking to reporters in Nice, Mr Estrosi said two people were killed inside the church.
Mr Estrosi said in a tweet said the church caretaker was among those attacked at the Basilica Notre Dame.
He appealed to the citizens of Nice to remain united.