She said the ban would come into force on Saturday, after an escalation of violence during protests on 1 October.
Ms Lam said the decision was taken because the situation could not be allowed "to get worse and worse".
Protesters, who have promised to defy the new law, immediately took to the streets in response.
Mask-wearing activists had also earlier called on others to wear masks in defiance of the government, which critics fear is becoming increasingly authoritarian.
Ms Lam said she was forced to implement the colonial-era law because the violence at the now-weekly protests was "destroying the city".
Observers say the regulation will be hard to enforce and hugely controversial: critics have warned the mask ban could be the first in a series of "draconian" measures.
"This is a watershed. This is a Rubicon," pro-democracy lawmaker Claudia Mo told news agency AFP. "And I'm worried this could be just a starter. More draconian bans in the name of law could be lurking around the corner."
The announcement has also prompted reaction from further afield, with Marta Hurtado, the United Nations human rights spokeswoman, noting at a press conference in Geneva that "any restriction must have a basis in law and be proportionate and as least intrusive as possible".
UK Foreign Secretary Dominic Raab, meanwhile, has said "political dialogue is the only way to resolve the situation".
Where does the ban apply?
Secretary for Security John Lee said the ban would apply for approved and unapproved public assemblies - rallies and marches - as well as in unlawful assemblies and riots.
The ban covers all kinds of facial covering, including face paint. Protesters have increasingly worn masks for a number of reasons, including to conceal their identities - from employers, parents and, in some cases, police - and to protect themselves from tear gas.
There are exemptions for people wearing masks for health reasons, or if required by their profession.
Ms Lam said "violence had been escalating to alarming levels" leading to a situation of "chaos and panic" in the city.
What is the Emergency Regulations Ordinance?
The legislation invoked by Ms Lam, called the Emergency Regulations Ordinance, dates to 1922 and has not been used in more than 50 years.
It enables the chief executive to bypass the normal legislative process, where bills have to go through the city's parliament, the Legislative Council.
The ERO was last used in 1967 to help stop riots in the territory's trading hub.
Ms Lam stressed the new regulation did not mean that Hong Kong was in a state of emergency. But she said the city was "in a state of serious public danger".
What else did Carrie Lam say?
The city's chief executive said what had been single rallies or marches, when the protests began, had spread to many areas across Hong Kong.
She said petrol bombs were being used inside closed spaces like railway stations, and that violent protesters had targeted public buildings and private properties.
She also accused protesters of not just criticising but "lynching" people with different views. It is unclear exactly what she was referring to.
According to the government, the percentage of demonstrators who are students has risen from 25% to 38%. Ms Lam said the mask ban would help prevent students breaking the law.
She also pointed out that similar bans on facial coverings were in place in other places around the world.
France to ban protest masks amid unrest
What is the background?
Hong Kong's protests started in June, sparked by proposals to extradite suspected criminals to mainland China.
The extradition bill has since been cancelled but protests have widened into pro-democracy and anti-police demonstrations.
Over the months, clashes between police and activists have become increasingly violent. On Tuesday, police shot a protester in the chest with a live bullet for the first time.
Authorities say the 18-year-old - who was attacking police and was arrested after being shot - is in a stable condition in hospital.
Hong Kong is a former British colony handed back to China in 1997.
It has a "one country, two systems" agreement that guarantees it some autonomy, and its people certain freedoms, including freedom of assembly and freedom of speech.
But those freedoms - the Basic Law - expire in 2047 and it is not clear what Hong Kong's status will then be.