WASHINGTON — Gen. John R. Allen, the four-star Marine Corps officer who served until earlier this month as the top commander in Afghanistan, will retire from the military to focus on “health issues within his family,” President Obama said on Tuesday.

General Allen was caught up in the scandal that led to the resignation of David H. Petraeus as the director of the Central Intelligence Agency. But last month, the Pentagon officially cleared him of misconduct after an investigation into his exchange of e-mails with Jill Kelley, a Tampa, Fla., woman who was also a friend of Mr. Petraeus’s. General Allen had gotten to know her when he was in a leadership role at the Central Command in Tampa.

Mr. Obama had nominated General Allen to be the supreme commander of NATO, but in the intervening weeks the general decided to retire.

“I told General Allen that he has my deep, personal appreciation for his extraordinary service over the last 19 months in Afghanistan, as well as his decades of service in the United States Marine Corps,” Mr. Obama said in a statement. “John Allen is one of America’s finest military leaders, a true patriot, and a man I have come to respect greatly.”