WASHINGTON — President Obama on Tuesday pardoned James E. Cartwright, a retired Marine Corps general and former vice chairman of the Joint Chiefs of Staff who pleaded guilty to lying to the F.B.I. about his discussions with reporters about Iran’s nuclear program, saving him from a possible prison sentence.

General Cartwright, who was a key member of Mr. Obama’s national security team in his first term and earned a reputation as the president’s favorite general, pleaded guilty late last year to misleading investigators looking into the leaking of classified information about cyberattacks against Iran.

He was due to be sentenced this month. His defense team had asked for a year of probation and 600 hours of community service, but prosecutors had asked the judge overseeing his case to send him to prison for two years.

Now, the retired general will be spared such punishment.

Both General Cartwright and his lawyer, Gregory Craig, a former White House counsel to Mr. Obama, thanked the president in statements. “The president’s decision is wise and just, and it achieves the right result,” Mr. Craig said. “It allows General Cartwright to continue his life’s work — to serve, protect and defend the nation he loves. It allows the nation to continue to benefit from his vast experience and knowledge.”