Apple must provide "reasonable technical assistance" to investigators seeking to unlock the data on Syed Rizwan Farook's iPhone 5C, US Magistrate Judge Sheri Pym of US District Court in Los Angeles ruled.
This includes disabling its auto-erase function, which activates after 10 consecutive unsuccessful passcode attempts, and allowing investigators to submit passcode guesses via electronic means.
Apple did not immediately respond to a request for comment on the ruling. The company has five business days to contest the order if it believes compliance would be "unreasonably burdensome," Pym said in her decision.
The US Attorney's Office in Los Angeles on Tuesday requested the court compel Apple to assist the investigation.
"Apple has the exclusive technical means which would assist the government in completing its search, but has declined to provide that assistance voluntarily," prosecutors said.
Tuesday's order comes a week after Federal Bureau of Investigation Director James Comey told members of Congress that investigators have been unable to access the contents of a phone belonging to one of the San Bernardino shooters. The Dec. 2 attack by Farook and his wife killed 14 people and injured 22 others, and the couple was later killed in a shootout with police.
Government officials have warned that the expanded use of strong encryption is hindering national security and criminal investigations.
Technology experts and privacy advocates counter that forcing US companies to weaken their encryption for law enforcement purposes would make private data vulnerable to hackers, undermine the security of the Internet and give a competitive advantage to companies in other countries.
Apple may say it cannot comply with the government's request on grounds its default encryption standards prevent it from being technologically capable of doing so. The company took that position in a case last year, telling a US judge in Brooklyn, New York, that it is "impossible" to unlock its devices that run an operating system of iOS 8 or higher.
The phone belonging to the Farook ran on iOS 9.
The government, however, said in its filing that it is asking for the disabling of "non-encrypted barriers that Apple has coded into its operating system."
Get Breaking news, live coverage, and Latest News from India and around the world on NDTV.com. Catch all the Live TV action on NDTV 24x7 and NDTV India. Like us on Facebook or follow us on Twitter and Instagram for latest news and live news updates.