Updated

James Comey, director of the Federal Bureau of Investigation, on Tuesday conceded that a mistake was made in the early days of the investigation into the San Bernardino, Calif., terrorism attack, making it harder to get data from one of the shooters’ phones.

Mr. Comey said, however, that even without that error, the government would still need Apple Inc.’s help to open the locked iPhone.

The FBI director’s discussion of the San Bernardino case came during a House Judiciary Committee hearing on the issue of encryption—the subject of a major legal battle between the FBI and Apple about the company’s refusal to help investigators open a phone seized in the probe of the California shooting that left 14 dead in December.

The hearing created the unusual spectacle of Mr. Comey, one of the nation’s highest-ranking law-enforcement officers, squaring off against Bruce Sewell, the top lawyer for Apple, one of the world’s most visible technology companies. Mr. Comey testified first, followed by Mr. Sewell.

Apple is fighting a court order to help the FBI bypass the passcode-security measures on the phone used by Syed Rizwan Farook, one of the two assailants. The FBI wants to disable a security feature that erases the phone’s memory after 10 failed password attempts.

Apple has argued that if San Bernardino County officials had not reset the cloud storage account connected to that phone, the FBI might have been able to access much more of the data on the phone by connecting the device to the Wi-Fi system in Mr. Farook’s apartment.

Mr. Comey conceded Tuesday that there is some truth to that argument, though he noted that even if the account hadn’t been reset, the two sides would still be in court.

“There was a mistake made in that 24 hours after the attack, where the county at the FBI’s request took steps that made it impossible later to cause the phone to back up to the iCloud,” Mr. Comey told the congressional committee, adding that, “We would still be in litigation, because there was no way we would have gotten everything off the phone from a backup.”

Apple and privacy experts are likely to seize on those comments to make the case that the company shouldn’t be forced to compensate for investigators’ mistake.

Separately, at a technology conference in San Francisco, Attorney General Loretta Lynch said she was “disappointed” by a federal judge’s ruling on Monday in New York that the government can’t compel Apple to help investigators extract data from a locked iPhone in a drug probe.

Ms. Lynch said Apple had agreed to help the government in similar instances in the past but pushed back in the New York case. She said she believes technology companies are subject to a “social compact” to comply with the law, but said law enforcement also needed to be clear and specific in what data it wants from devices.

In prepared remarks, Ms. Lynch took a conciliatory tone, saying Washington and Silicon Valley should work together. But the subsequent question-and-answer session reflected the tension between Apple and law enforcement.

“Do we let one company, no matter how great the company, no matter how beautiful their devices, decide this issue for all of us?” Ms. Lynch asked.

The Justice Department’s argument that law enforcement must be able to open phones when it obtains a valid court order was met by skepticism from some lawmakers.

Rep. John Conyers, (D., Mich.), the Judiciary Committee’s top Democrat, said he has been reluctant to support the Justice Department and the FBI on the issue. The growth of encryption means “we will all have lockboxes in our lives that only we can open and in which we can store all that is valuable to us,” he said. “There are lots of good things about this.’’

Others were more open to law-enforcement’s viewpoint.

“The question for Americans and lawmakers is not whether or not encryption is essential, but instead, whether law enforcement should be granted access to encrypted communications when enforcing the law and pursuing their objectives to keep our citizens safe,’’ said Rep. Robert Goodlatte, (R., Va.), the committee’s chairman.

Click for more from The Wall Street Journal.