BOSTON — A Massachusetts prosecutor defended Wednesday a state ban on secret audio recordings of police and government officials, asking an appeals court to overturn a decision that found the prohibition unconstitutional.

At a hearing before the U.S. First Circuit Court of Appeals, free speech groups countered that such recordings are protected by the First Amendment and that Massachusetts’ law is out of step with national norms, especially in an era when nearly everyone has a recording device in their pocket.

They argued that a lower court’s ruling that people can’t be arrested for secretly recording police should be upheld. A panel of three judges is expected to decide the case later.

U.S. District Court Chief Judge Patti Saris ruled in 2018 that Massachusetts law “may not constitutionally prohibit the secret audio recording of government officials, including law enforcement officials, performing their duties in public spaces, subject to reasonable time, manner, and place restrictions.”

But Suffolk County District Attorney Rachael Rollins, who is Boston’s top prosecutor, appealed, arguing the state’s 1968 wiretap law is a critical protection ensuring citizens know when they’re being recorded.

State Attorney General Maura Healey’s office, which is representing Rollins in the appeal, cites in its legal brief a number of hypothetical scenarios where secret recordings of public officials might harm average citizens.

Among them: when a police officer encounters a victim or witness to a crime in the street, an elected official speaks one-on-one with a constituent at a senior center, or when a social worker counsels a sexual assault victim in a hospital corridor.

But the American Civil Liberties Union of Massachusetts, which is representing two Boston residents who frequently record police activity, argued the Constitution’s First Amendment “unambiguously” protects the right to peacefully record and observe police activity in a way that does not interfere with the officers’ performance of their duties.

It also argued that lawmakers, based on legislative records from the 1960s, clearly intended to protect citizens from being surreptitiously recorded by police or telephone companies — not to shield public officials from scrutiny.

“The government should have an interest in encouraging members of the public to create accurate records of what police officers say in public when they think no one is recording them,” the ACLU wrote in its legal brief.

Project Veritas, a conservative organization known for publishing undercover investigations of groups such as the now-defunct Association of Community Organizations for Reform Now, or ACORN, also sued to overturn the law.

The group said the law effectively prevents it from conducting its work — which involves equipping operatives with secret cameras and recording devices — in Massachusetts.

It argues that the state law is an outlier in the country because most states allow for some form of secret recording of public officials.

Project Veritas also argued that privacy and recording norms are evolving rapidly because surveillance technology — from nanny cams to video doorbells — is increasingly common.

“People record life events, share them with others, publish them as news, and connect with the world in ways unimaginable when Section 99 was passed in 1968,” the organization argued, referring to the state anti-wiretap law. “Massachusetts should welcome — not imprison — citizens using technology to advance speech.”