A retired four-star Marine Corps general who served as the nation’s second-ranking military officer pleaded guilty Monday to a federal felony charge of lying to the FBI in a probe of a leak of classified information about a covert U.S.-Israeli cyberattack on Iran’s nuclear program.

James E. “Hoss” Cartwright, who served as vice chairman of the Joint Chiefs of Staff before he retired in 2011, entered his plea before U.S. District Judge Richard J. Leon of Washington hours after the charge was announced by the office of U.S. Attorney Rod Rosenstein of Maryland.

A senior Obama administration official in June 2013 acknowledged that Cartwright was the target of a Justice Department investigation into a leak to New York Times reporter David E. Sanger of details about a highly classified operation to hobble Iran’s uranium-enrichment capability through cybersabotage — an effort not acknowledged by Israel or the United States.

In court documents, Cartwright admitted to falsely telling FBI investigators he did not provide or confirm classified information to Sanger for a June 2012 newspaper article and his book, “Confront and Conceal.” Cartwright also admitted that he had lied to investigators when he said he had not confirmed classified information in an email to Newsweek correspondent Daniel Klaidman.

In a statement after his plea, Cartwright denied being the source of the story but said, “It was wrong for me to mislead the FBI [in a voluntary interview] on Nov. 2, 2012, and I accept full responsibility.”

Cartwright, 67, added, “I knew I was not the source of the story and I didn’t want to be blamed for the leak. My only goal in talking to the reporters was to protect American interests and lives.”

The false statements charge carries a maximum prison term of five years. But under a plea agreement, both sides estimated that federal guidelines would call for a sentence of zero to six months. Each side also reserved the right to argue for a lower or higher sentence and acknowledged that Leon may depart from the guidelines at a sentencing set for Jan. 17.

Part of that proceeding, Leon said Monday, might be held in secret to discuss classified information.

In a statement, the New York Times said that neither it nor Sanger would discuss the sourcing of information beyond what was published and that it was disappointed that the Justice Department had gone forward with the investigation.

“These investigations send a chilling message to all government employees that they should not speak to reporters. The inevitable result is that the American public is deprived of information that it needs to know,” the Times said. “”Reporting like this serves a vital public interest: explaining how the United States is using a powerful new technology against its adversaries and the concern that it raises about how similar weapons can be used against the U.S.”

Rosenstein in a statement after the hearing said, “People who gain access to classified information after promising not to disclose it must be held accountable when they willfully violate that trust.”

FBI investigators focused on Cartwright in the fall of 2012, according to people familiar with the case who spoke on condition of anonymity because of the sensitivity of the investigation.

Part of the challenge of preparing the case was determining to what extent authorities who control the declassification of information — in this case, the White House and intelligence community — were willing to divulge details.

The false statement charge was, practically speaking, the stiffest charge the government could bring given such roadblocks, several current and former law enforcement officials said. By 2014, White House officials did not want to declassify material important to the case, officials said.

The Obama administration was also sensitive to its ally Israel’s concerns about revealing information in a court case about the cyber-operation.

But, during interviews with FBI special agents, Cartwright made false statements that gave prosecutors grounds to charge him.

Cartwright had White House authorization to speak with reporters, according to people familiar with the matter. However, in court documents, Cartwright and prosecutors stated that classified disclosures to the journalists were not authorized.

Cartwright’s attorney, Gregory Craig, said in a statement that in conversations with Sanger and Klaidman, Cartwright “was engaged in a well-known and understood practice of attempting to save national secrets, not disclosing classified information. His effort to prevent publication of information that might harm American lives or national security does not constitute a violation of any law.”

Craig added that Cartwright’s “offense was in statements he made to FBI agents investigating a leak — and that is the entire basis of his plea.”

Cartwright helped design the cybercampaign against Iran under President George W. Bush and was involved in its escalation under President Obama. Details of the joint program, including its code name, Olympic Games, were revealed by Sanger in 2012.

The sabotage of Iranian uranium centrifuges by the computer worm dubbed Stuxnet — the first known use of computer code to destroy another country’s critical system — had emerged two years earlier, and security experts speculated that it was the work of the United States and Israel.

Disclosures about the operation set off a political controversy, with congressional Republicans charging that the White House had deliberately leaked information to enhance Obama’s national security credentials as he sought reelection.

Legal analysts noted that Cartwright was being charged in connection with the leak investigation — and not with the leak itself. Nonetheless, the prosecution shows the Obama administration is seeking to send a message about unauthorized leaks of classified information, said Stephen Vladeck, a law professor at the University of Texas.

“I think the reality is that this trend will not stop leaking,” Vladeck said. “But I have to think it is intended to dissuade it.”

No matter the source, Vladeck added, the information about the cybersabotage operation was in the public interest. “When the government is approaching the line of acts of war against a foreign sovereign, I have this naive and perhaps antiquated view that people have a right to know about it — maybe not as it happened, but at some point afterward.”

A previous version of this article incorrectly identified James E. “Hoss” Cartwright as deputy chairman of the Joint Chiefs of Staff before he retired in 2011. He was vice chairman. This version has been corrected.