Petraeus submitted his letter of resignation to President Barack Obama on Friday, according to a statement by Director of National Intelligence James R. Clapper.
The president accepted the resignation, saying the general has "made our country safer and stronger."
Petraeus said in a statement that he had shown "extremely poor judgment" in having an affair.
Petraeus took the director's post in September 2011.
The Associated Press contributed to this report.