President Barack Obama said Petraeus had led the Central Intelligence Agency "with characteristic intellectual rigor, dedication, and patriotism.
"I am completely confident that the CIA will continue to thrive and carry out its essential mission, and I have the utmost confidence in Acting Director Michael Morell and the men and women of the CIA who work every day to keep our nation safe," the president said in a written statement.
"Going forward, my thoughts and prayers are with Dave and Holly Petraeus, who has done so much to help military families through her own work. I wish them the very best at this difficult time," Obama continued.
Director of National Intelligence James Clapper issued a statement that did not specify a reason for Petraeus's departure but praised his colleague extensively.
"From his long, illustrious Army career to his leadership at the helm of CIA, Dave has redefined what it means to serve and sacrifice for one's country," said Clapper.
Petraeus went to work as CIA chief in September 2011 after heading up the war in Afghanistan. He had drawn fire in the aftermath of the Sept. 11 attack on the American compound in Benghazi, Libya. His departure comes barely a week before he was scheduled to testify about the assault in closed-door sessions with the intelligence committees of the Senate and House of Representatives.
Petraeus' resignation letter, quoted by several news outlets, centered on his personal behavior.
"Yesterday afternoon, I went to the White House and asked the President to be allowed, for personal reasons, to resign from my position as D/CIA. After being married for over 37 years, I showed extremely poor judgment by engaging in an extramarital affair. Such behavior is unacceptable, both as a husband and as the leader of an organization such as ours," he said. "This afternoon, the President graciously accepted my resignation."
Petraeus, 60, has been described as the father of the military's counterinsurgency doctrine. The charismatic officer had been cited as a possible future presidential or vice presidential prospect.
His wife Holly has worked inside the Obama Administration, serving at the Consumer Financial Protection Bureau.