Apple’s lawyers believe forcing America’s largest company to help the government crack open one of its iPhones would violate the US constitution and be a misinterpretation of a 227-year-old law.

The 36-page legal brief, submitted on 25 February, is Apple’s first formal rebuttal to a court order to write and sign software that would make it easier for investigators to open a phone used by San Bernardino gunman Syed Farook, who, with his wife Tashfeen Malik, killed 14 and wounded 22 on 2 December.

The tech firm’s attorneys argue the government seeks “a dangerous power that Congress and the American people have withheld: the ability to force companies like Apple to undermine the basic security and privacy interests of hundreds of millions of individuals around the globe.”

Facebook and Twitter will join a supporting brief; Microsoft general counsel Brad Smith told the house judiciary committee on Thursday that his company would do the same, indicating that tech companies were coalescing around support for Apple despite extensive outreach by senior Obama administration officials earlier this year. “The industry is aligned and working on a joint submission to the court,” said an industry representative.

Apple’s legal team, led by George W Bush’s former solicitor general Theodore Olson, portrayed the government not only as indifferent to privacy concerns, but placing the security of its customers’ digital lives at risk of attack, suggesting that the US was unwittingly conducting a cyberattack on millions of Apple users.

The Justice Department was seeking to “roll back by judicial decree” the measures Apple takes through its most recent mobile encryption protocols to protect “financial records and credit card information, health information, location data, calendars, personal and political beliefs, family photographs, information about [customers’] children.”

Apple also accused the government of outright dishonesty over claims, repeatedly made by FBI director James Comey, that it was not seeking to set a precedent. Comey conceded earlier on Thursday that the resolution of the Apple-FBI showdown would inevitably “guide how other courts handle similar requests” to force access on locked mobile devices.

In a legal brief that reflected a battle for public opinion as much as for legal victory, Apple said it would continue to “strongly” support law-enforcement efforts to combat terrorism – a reference to its long record of cooperation with “legally valid” government data requests – but said it cannot comply with an “unprecedented” order placing constitutional rights in jeopardy.

Apple says the court order violates American free speech law under the first amendment and due process protections under the fifth amendment, and that it leans too heavily on the so-called All Writs Act, a statute dating back to 1789 that gives courts broad authority to ensure orders are fulfilled.

Another statute at issue is the Communications Assistance for Law Enforcement Act (CALEA) which Apple says the government ignores, but which the government says does not apply in this case. In 1996, a federal court ruled that computer code is protected speech under the first amendment. In an illustration of the cyclical nature of debates over technology and society, the plaintiff in that case was a University of California Berkeley graduate student who had developed an encryption algorithm.

The government paints a very different picture. US attorneys say Apple is placing marketing over national security and that it only seeks help in one extraordinary case – that of the deadliest terrorist attack on US soil since September 11. It also states that American companies are required to comply with American law when it is technically possible.

Justice Department spokesperson Melanie Newman, responding to the Apple brief, said the tech company was the only one departing from long-established norms.

“Law enforcement has a longstanding practice of asking a court to require the assistance of a third party in effectuating a search warrant,” she said. “When such requests concern a technological device, we narrowly target our request to apply to the individual device. In each case, a judge must review the relevant information and agree that a third party’s assistance is both necessary and reasonable to ensure law enforcement can conduct a court-authorized search. Department attorneys are reviewing Apple’s filing and will respond appropriately in court.”

Apple argued that any government effort to compel a company to create access into a product for law enforcement was “a political question, not a legal one” – a move that could add to pressure, which tech companies have thus far resisted, to pass a law mandating such access.

Apple’s user-privacy chief, Erik Neuenschwander, all but accused the FBI of technical illiteracy in a supplemental declaration refuting the government’s claim that since Apple can always destroy the code permitting it access into Farook’s iPhone, it was not actually mandating the creation of a back door.

Replicating a code once engineered is “as easy as a computer key stroke because the underlying code is persistent”, Neuenschwander stated. The logs Apple would have to keep documenting the creation process – likely to be necessary from a legal compliance perspective – would provide the “government or anyone else... [with] a roadmap to recreate Apple’s methodology, even if the system and underlying code no longer exist.”

The team also accused the government in its brief of cynicism with its invocation of terror. “[B]y invoking ‘terrorism’ and moving ex parte behind closed courtroom doors, the government sought to cut off debate and circumvent thoughtful analysis,” counsel wrote.

But Apple’s legal team argues complying with the court order would set a precedent that lets investigators regularly force tech companies to remake their products for any run of the mill investigation.

If Apple loses, its lawyers say there is nothing to stop the government from demanding Apple write software to turn on the iPhone camera of one user or the microphone of another. Moreover, the company says, it has already assisted in the investigation.

“Apple responded immediately, and devoted substantial resources on a 24/7 basis to support the government’s investigation of this heinous crime,” said the brief.

Counsel went on to blame the government for forcing a password reset of Farook’s iCloud account. Seeking Apple’s assistance more closely at the beginning of the case, its lawyers said, “could have obviated the need to unlock the phone and thus for the extraordinary order the government now seeks.”

“The government says: ‘Just this once’ and ‘Just this phone.’ But the government knows those statements are not true,” the filing says. “Once the floodgates open, they cannot be closed.”

That argument is, in some ways, Apple’s greatest strength and weakness in its battle not only in court but with public opinion, which narrowly backs the government, according to polls. It is unknown what evidence, if any, the government could obtain by accessing Sayeed Farook’s iPhone 5c. But the FBI claims it can achieve a very specific benefit (evidence) if Apple helps it get inside a very specific phone (Farook’s).

And while consumers say they care about privacy, Apple is forced to argue that this would harm unspecified consumers in an unspecified future when thieves or bad actors in governments can easily break into stolen iPhones because of how Apple helped the government.

Apple has made consumer privacy a core issue during the past two years, as Silicon Valley tries to recover from the surveillance revelations of Edward Snowden, the former US spy contractor. In response, the company has added extra security features to its iPhones such as encryption that, Apple says, prevents it from unlocking a phone without a user’s passcode. Apple doesn’t have this passcode.

Taking aim at the government’s argument that Apple can create a one-time exploit permitting the FBI access to a single phone, Apple argued that it would have to spend “weeks” engineering a functionally different operating system, testing it against unanticipated security flaws and validating its functions, and potentially repeating the entire process for each law-enforcement request.

Although the FBI’s Comey and sympathetic lawmakers argued on Thursday that Apple’s compliance on the iPhone 5C Farook used is indistinguishable from honoring any other warrant, the company contended it was being press-ganged into doing the government’s work for it.

“Federal courts themselves have never recognized an inherent authority to order non-parties to become de facto government agents in ongoing criminal investigations”, Apple contended, further arguing that the Obama administration’s decision against seeking legislation requiring companies to build “back doors” into their encryption mechanisms indicates that the FBI lacks the power it seeks in the present case.

People close to the case – on both sides – expect Apple may face a tough sell this first round in the Central District of California court. The magistrate, Judge Sheri Pym, is a former federal prosecutor and has already issued an order in favor of the government. But Apple chief executive Tim Cook said he is prepared to take the case through a lengthy appeals process that could go all the way to the supreme court.

Apple’s uber-lawyer team, which includes Theodore Boutrous, a partner at Gibson, Dunn & Crutcher with an expertise in constitutional law, and Marc Zwillinger, a surveillance law pioneer, also suggests the company is girding for a multi-round fight.

A hearing on the case is set for 22 March.