Convicted pedophile Jeffrey Epstein was so thrilled with the sweetheart plea deal his legal dream team scored for him in Florida that he threw in an added bonus — nearly $1 million worth of donations to their favorite charities, including a tony Manhattan prep school.

In 2007, while two Manhattan-based criminal defense lawyers were finalizing Epstein’s deal, which included 13 months in a Palm Beach County jail and freedom from federal criminal prosecution, Epstein was writing checks to their charities.

Epstein’s C.O.U.Q. nonprofit donated $500,000 in 2007 to the Ramaz School on the Upper East Side, where attorney Jay Lefkowitz was a prominent member of the school’s Orthodox Jewish community.

Epstein’s private foundation also donated $250,000 to the Washington-based Foundation for Criminal Justice, where another attorney, Gerald Lefcourt, was a board member in 2007, public filings show.

Both of the contributions were one-time donations from the charity, which was founded in 1998 by Epstein and former gal pal Ghislaine Maxwell, the daughter of the late British media mogul Robert Maxwell who has been accused by three women of procuring girls to work as sex slaves for Epstein.

It’s not clear what prompted the donations, and neither Lefcourt nor Lefkowitz returned The Post’s emails and calls seeking comment.

Lefkowitz was a senior adviser to both Presidents Bush, and the attorney’s three children attended the school. Rabbi Haskel Lookstein, who served as principal of the school between 1966 and 2015, married Lefkowitz and his wife, Elena Neuman, in 1991.

Neuman, a documentary filmmaker, has made films for the Ramaz School, according to her LinkedIn profile. The couple donated between $25,000 and $99,000 to the school’s annual campaign in 2010, according to the Ramaz Magazine.

In a letter sent to Ramaz parents, school officials said they did not know that the 2007 contribution came from Epstein and were only recently made aware of it.

“This gift opportunity was brought to Ramaz by a community member and was used to establish an educational program,” said the letter, which did not identify the “community member.”

A spokeswoman for Ramaz refused comment.

Calls to the Foundation for Criminal Justice, a charity that promotes the work of criminal defense lawyers, did not return requests for comment.

Epstein’s lenient plea deal saw him spend 13 months in jail, when he was allowed to return to his office during the day. He had to register as a sex offender and pay restitution to a handful of victims.

Epstein was arrested last month in New Jersey and charged with sexually abusing minors at his homes in Florida and Manhattan between 2002 and 2005.