Government surveillance programs are on the defensive.

On Wednesday, the New York Police Department agreed to expunge more than a half million names from its stop-and-frisk database – another blow to the embattled crime-fighting tactic that Mayor Michael Bloomberg has hailed as a key policy in the city’s plunging crime rate.

And the National Security Administration, already under fire from revelations that it has been vacuuming up vast amounts of Americans’ private phone and e-mail data, likely will face increased scrutiny as it has also been sifting through some of the actual content – a fact previously undisclosed – according to a New York Times investigation.

The Obama administration has defended the secret NSA program as an essential tool in the fight against terrorism.

Both practices, while involving separate issues of safety, have reignited questions about the ways government agencies keep tabs on millions of citizens – as well as the various techniques they employ to fight both crime and terror.

Civil liberties advocates are seeking to put government officials on their heels as they fight to swing the constitutional pendulum back toward protection of privacy.

“There has to be a balance struck between the need to protect us, and the need to protect the constitution,” says Randolph McLaughlin, co-chair of the civil rights practice group at Newman Ferrara LLP in New York. “And that’s the wavering line we’ve been adjusting since 9/11, frankly.” [Editor's note: The original version of this story had an incorrect first name for Mr. McLaughlin.]

Wednesday’s stop-and-frisk settlement is the latest sign the line may be wavering back toward privacy. The Bloomberg administration, which has been fighting challenges to the program vociferously for over a decade, nevertheless agreed to voluntarily delete about 565,000 names and addresses that police officers had collected from those who were stopped and frisked.

The agreement stemmed from a lawsuit brought by the New York Civil Liberties Union in 2010, which challenged the collection and use of this data. But police had been collecting such data for over a decade, gathering more than 2.7 million names and addresses through the program.

But in 2010, against the objections of Mayor Bloomberg and Police Commissioner Raymond Kelly, the state passed a law forcing the NYPD to expunge the information of anyone who was not charged with a crime – about 90 percent of the data. In the new settlement, the remaining names and addresses will be deleted within 90 days.

But the stop-and-frisk tactic faces its biggest test sometime in the next few weeks, when a federal judge is expected to rule on whether the controversial police practice violates the Fourth Amendment’s prohibition against unreasonable search and seizure, as well as the Fourteenth Amendment’s equal protection clause, which bars racial discrimination. Roughly 85 percent of those stopped are black or Latino, and 9 out of 10 of all stops result in no arrest or further action.

“They’re under a lot of pressure from both the federal court and potentially the Justice Department to take a hard look at this thing,” says Mr. McLaughlin. “And I think the case is critical to the continuation of the policy, because if the case is successful for the plaintiffs, then there will be more likely than not a federal monitor appointed.”

The Justice Department has already told the judge that a federal monitor is the most appropriate remedy, should she find stop-and-frisk unconstitutional.

At the same time, the Obama administration continues to defend the secret NSA databases against charges that it violates the constitution’s protections against unwarranted searches, as an issue of national security. But the New York Times investigation revealed that in addition to its complex dragnet of American’s phone and Internet data, analyzing only connections to previously known suspects, the spy agency also scans all texts and e-mails sent overseas with a keyword search.

But these keywords need not have any direct connection to a known terror suspect. An e-mail or text that simply mentions anything related to the keywords used, even if incidental or coincidental, can be sent to an analyst for review. This has never been acknowledged since details of the NSA program first came to light with the leaks by Edward Snowden.

This brings constitutional questions about the NSA program even more to the fore, say experts, and it adds another layer to charges that the government surveillance program intrudes too far into Americans’ private affairs.

The program “involves a breathtaking invasion of millions of people's privacy," wrote Jameel Jaffer, American Civil Liberties Union deputy legal director, in a statement. "The government's scrutiny of virtually every international e-mail sent by Americans will have extraordinary consequences for free expression. Americans will inevitably hesitate to discuss controversial topics, visit politically sensitive websites, or interact with foreigners with dissenting views. By injecting the NSA into virtually every cross-border interaction, the US government will forever alter what has always been an open exchange of ideas."