A federal appeals court sided with Microsoft on Thursday in a case over whether the U.S. government could force the tech giant and other companies to hand over customer emails stored overseas.

The decision is a victory for privacy advocates and reverses a 2014 court order that required Microsoft to turn over email content stored on a server in Ireland. The original warrant that sparked the legal showdown was for emails connected to a narcotics case.

The latest decision came from the U.S. Court of Appeals for the Second Circuit in New York, where Judge Susan Carney found that the federal Stored Communications Act only applies to data stored in the United States — and thus can't be used to force a company to produce information from servers outside the country.

Without the warrant, the government has to go through a much lengthier process set up through a mutual legal assistance treaty with the Irish government to obtain the data. Ireland filed a brief supporting Microsoft in the case, as did many tech companies, including Apple and Cisco.

Tech companies often have data centers all over the world and user data may be moved around so that it could be backed up or more easily accessed by users. And Microsoft argued that turning over data stored overseas to U.S. authorities could ultimately put the privacy of Americans in jeopardy.

"If the Government prevails here, the United States will have no ground to complain when foreign agents — be they friend or foe — raid Microsoft offices in their jurisdictions and order them to download U.S. citizens’ private emails from computers located in this country," the company argued in its opening brief of the appeal.

Microsoft President and Chief Legal Officer Brad Smith said the company was pleased with the court's ruling. "The decision is important for three reasons: it ensures that people’s privacy rights are protected by the laws of their own countries; it helps ensure that the legal protections of the physical world apply in the digital domain; and it paves the way for better solutions to address both privacy and law enforcement needs," Smith said in an emailed statement.

Privacy advocates also celebrated the decision. "This is a groundbreaking decision that helps protect privacy rights around the world," the Electronic Frontier Foundation, which had submitted a brief supporting Microsoft in the case, said in a statement.

The government was less enthusiastic.

“We are disappointed with the court’s decision and are considering our options," Justice Department spokesman Peter Carr said in an emailed statement. Being able to quickly access information stored by American companies overseas is important for ensuring public safety and obtaining justice for crime victims, he added.