The judge in Brooklyn denied a motion by the US Justice Department to get Apple to unlock a phone in a drug case.
In an unrelated case, the FBI wants Apple to unlock the iPhone of Syed Rizwan Farook, who killed 14 people in San Bernardino, California in December.
But Apple has resisted, calling that demand "dangerous" and "unprecedented".
The ruling in Brooklyn on Monday centres on the same point as the San Bernardino case.
Fourteen people were killed and 22 injured when gunman Farook and his wife Tashfeen Malik opened fire in the Californian city in December.
A court order in California demanded Apple help circumvent security software on Farook's iPhone, which the FBI said contains crucial information.
Apple's CEO Tim Cook said the request was "an overreach by the US government" and risked giving authorities "the power to reach into anyone's device to capture their data". Last week, the company asked a court to overturn the ruling.
The same Act from 1789 that was used by the FBI in the San Bernardino request was applied in the Brooklyn case. But Judge James Orenstein said the Act was not applicable in this case, adding that it was not right to impose "on Apple the obligation to assist the government's investigation against its will".
The US Justice Department said it planned to appeal against the Brooklyn ruling.