It was the princess and the pedo.

Jeffrey Epstein attended the 18th birthday of pal Prince Andrew’s daughter Princess Beatrice just days before he was arrested on child-prostitution charges in 2006, according to a new report.

Epstein flew in for the lavish, half-million-dollar soiree at Windsor Castle with his then-girlfriend and accused procuress Ghislane Maxwell, the Sun reported.

Also reportedly in attendance was rape-accused movie mogul Harvey Weinstein.

The Duke of York is among several prominent men accused of sleeping with Epstein’s underage victims — a charge he has denied.

But the birthday bash revelations just proves how close-knit the two men were, a source told the Sun.

“It goes to show how Epstein worked his way into the very heart of the British establishment — rubbing shoulders with royalty at a palace,” the person said.

Epstein was arrested eight days after the July 15, 2006, party — but he and Andrew remained friends until 2010, the Sun reported.

Prosecutors allowed Esptein to quietly plead guilty in 2008 to charges of soliciting an underage girl for prostitution. He was busted again July 6, of this year and charged with sex-trafficking for preying on girls in his Manhattan townhouse and Florida mansion, but killed himself in a Manhattan lock-up on Aug. 10 before he could face justice.

But Prince Andrew continues to face intense scrutiny over his ties — so much so that he’s disabled comments on his official Instagram.

Andrew’s spokesman declined to comment about “guests at a private event.”