THE man in charge of the US's spy agency has left his post after admitting he had an extra-marital affair.

David Petraeus stepped down as head of the CIA last night after his letter of resignation was accepted by President Barack Obama.

Petraeus said in a message to his colleagues at the CIA that he was resigning because he had been unfaithful to his wife.

Petraeus said: "After being married for over 37 years, I showed extremely poor judgment by engaging in an extra-marital affair. Such behaviour is unacceptable, both as a husband and as the leader of an organization such as ours."

He said the President "graciously accepted" his resignation.

Mr Petraeus became CIA boss in 2011 after heading international forces in Iraq, then in Afghanistan.

He was the highest-profile military officer of the post-9/11 years, and was instrumental in running the "surge" strategy in Iraq and implementing a counter-insurgency strategy in Afghanistan.

In a statement, Mr Obama said Mr Petraeus had "provided extraordinary service to the United States for decades", citing both his time as CIA director and service to the military.

He said: "By any measure, through his lifetime of service, David Petraeus has made our country safer and stronger.

"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."

CIA deputy director Michael Morell will serve as acting director of the agency.