While he was director of the CIA, Petraeus wrote a letter supporting the child-custody fight of the “psychologically unstable” twin sister of his close friend Jill Kelley — whose bombshell claims of being threatened by his lover led to the top spy’s resignation last week, sources told The Post.

The four-star general’s letter to the court — written in the past two months — supported a motion to overturn a ruling made nearly a year earlier by a judge who resoundingly denied custody to Kelley’s sister, Natalie Khawam, because of serious reservations about her honesty and mental stability, court records show.

Oh, my! Over/under on a nasty case of amnesia coming next? Perhaps we will find out that the twin is actually Kelley’s mother, transformed into her twin by a nefarious villain, who trapped her for years in his hidden lair?