The state Supreme Court Appellate Division ruling won't put any new information in prosecutors' hands. Facebook had lost earlier rulings and already turned the data over. But the case has been closely watched by social media companies, civil libertarians and prosecutors.
Facebook said it was weighing its options for continuing the fight.
"We continue to believe that overly broad search warrants — granting the government the ability to keep hundreds of people's account information indefinitely — are unconstitutional and raise important concerns about the privacy of people's online information," Facebook, which is based in Menlo Park, California, said in a statement.
The Manhattan district attorney's office, meanwhile, noted the unanimous decision from the Appellate Division's First Department about the warrants, which a lower-court judge had approved at the outset. The 381 warrants helped build a massive disabilities benefits fraud case against police and fire department retirees, and 108 people have pleaded guilty.
"In many cases, evidence on their Facebook accounts directly contradicted the lies the defendants told to the Social Security Administration" about being too psychologically devastated to work, district attorney's office spokeswoman Joan Vollero said Tuesday.
Some defendants disclosed on Facebook that they flew helicopters, traveled overseas, did martial arts and otherwise led active, full lives.
Tuesday's ruling centered on procedural questions about when a search warrant can be challenged. The court said Facebook wrongly argued it could legally stop prosecutors from gathering the information, as opposed to defendants arguing for keeping it out of court afterward.
But "our holding today does not mean that we do not appreciate Facebook's concerns about the scope of the bulk warrants issued here or about the district attorney's alleged right to indefinitely retain the seized accounts of the uncharged Facebook users," the five-judge panel wrote.
Facebook can contain more intimate personal information than someone's home, the judges noted, and only 62 of the people targeted in the 381 warrants have been charged.
Prosecutors have said they gave the initial judge 93 pages of details on why all the accounts were targeted.
A Manhattan judge OK'd the warrants in July 2013, saying law enforcement has authority to search massive amounts of material to seek evidence.
Facebook said prosecutors cast too wide a net. Google, Twitter and other online players joined the case on Facebook's side, as did the American and New York civil liberties union.
NYCLU staff attorney Mariko Hirose said the group was disappointed that Tuesday's ruling didn't address the privacy issues in the case more directly.