Apple will contest a court order asking it to help FBI investigators access data on the phone belonging to San Bernardino gunman Syed Rizwan Farook.
The company had been ordered to help the FBI circumvent security software on Farook's iPhone, which the FBI said contained crucial information.
In a statement, Apple chief executive Tim Cook said: "The United States government has demanded that Apple take an unprecedented step which threatens the security of our customers."
"We oppose this order, which has implications far beyond the legal case at hand."
Since September 2014, data on the latest Apple devices - such as text messages and photographs - have been encrypted by default.
If a device is locked, the user's passcode is required to access the data. Entering an incorrect code 10 times will automatically erase the phone's data, if this option has been enabled.
Apple says even its own staff cannot access the data - a move the company made following the Edward Snowden revelations into government surveillance.
The FBI has asked Apple to do two things.
Firstly, it wants the company to alter Farook's iPhone so that investigators can make unlimited attempts at the passcode without the risk of erasing the data.
Secondly, it wants Apple to help implement a way to rapidly try different passcode combinations, to save tapping in each one manually.
The FBI wants to use what is known as a "brute force" attack, trying out every combination until stumbling across the correct one and unlocking the phone.
Farook is understood to have used a four-digit passcode which means there are 10,000 possible combinations.
Apple said the FBI's demands set "a dangerous precedent".
"The FBI wants us to make a new version of the iPhone operating system, circumventing several important security features, and install it on an iPhone recovered during the investigation," wrote Mr Cook.
"The government is asking Apple to hack our own users and undermine decades of security advancements that protect our customers.
"Opposing this order is not something we take lightly. We feel we must speak up in the face of what we see as an overreach by the US government."
Farook and his wife killed 14 people in the California city last December before police fatally shot them.