The company’s statement did not say whether Apple engineers would help the government get into the phones themselves. It said that “Americans do not have to choose between weakening encryption and solving investigations” because there are now so many ways for the government to obtain data from Apple’s devices — many of which Apple routinely helps the government execute.

It will not back down from its unequivocal support of encryption that is impossible to crack, people close to the company said.

Justice Department officials said that they needed access to Mr. Alshamrani’s phones to see data and messages from encrypted apps like Signal or WhatsApp to determine whether he had discussed his plans with others at the base and whether he was acting alone or with help.

“We don’t want to get into a world where we have to spend months and even years exhausting efforts when lives are in the balance,” Mr. Barr said. “We should be able to get in when we have a warrant that establishes that criminal activity is underway.”

The confrontation echoed the legal standoff over an iPhone used by a gunman who killed 14 people in a terrorist attack in San Bernardino, Calif., in late 2015. Apple defied a court order to assist the F.B.I. in its efforts to search his device, setting off a fight over whether privacy enabled by impossible-to-crack encryption harmed public safety.

The San Bernardino dispute was resolved when the F.B.I. found a private company to bypass the iPhone’s encryption. Tensions between the two sides, however, remained, and Apple worked to ensure that neither the government nor private contractors could open its phones.