The ban on smartphones, tablets and other connected devices, which will apply to pupils up to the age of 14-15, fulfils a campaign promise by centrist President Emmanuel Macron, while being derided as "cosmetic" by the opposition.
MPs of Macron's centrist LREM party and its allies gave final approval to the bill, while lawmakers on the left and right abstained from the vote, calling the law a "publicity stunt" that would change nothing.
Under the new law, schools may make exceptions for "pedagogical use", extra-curricular activities, or for disabled pupils.
Secondary schools for their part can decide individually whether to impose a partial or total ban on connected devices.
A previous law, passed in 2010, already prohibited smartphone use during class.
Education Minister Jean-Michel Blanquer said the earlier law did not apply across the board and lacked teeth, while the new law moves France "into the 21st century".
"It sends a message to French society" as well as countries around the world, he said.
Nearly nine in 10 French teens aged 12 to 17 own a smartphone.