Katie Holmes rocked out onstage with Jamie Foxx, Lenny Kravitz — and Colin Powell — at Ron Perelman’s Apollo in the Hamptons benefit Saturday night.

The actress jumped onstage with performers including Pharrell Williams, the Roots and Ciara. They were joined by Ellen DeGeneres and former Secretary of State Powell, who even sang a few lines of Robin Thicke’s summer hit “Blurred Lines.”

A relaxed and happy-looking Holmes, who wore a black cocktail dress and attended the party at Perelman’s famous Hamptons estate the Creeks with two female friends, was later heard saying, “I haven’t had such a good time in so long.”

She danced all night and was seen shaking it with Foxx. Sources say Holmes and Foxx “are old friends.”

Penny Marshall and Fran Lebowitz were spotted sneaking outside to smoke. When Anjelica Huston and Lebowitz were asked to pose for a picture by a staffer who asked to capture their “beautiful faces,” Lebowitz replied, “You should have asked us in the ’70s.”

Other performers at the bash headlined by Kravitz included Jon Bon Jovi, Mary J. Blige and Darlene Love.

The crowd offstage was just as starry, including Billy Joel, Donna Karan, Calvin Klein, Howard Stern, Matt Lauer and Savannah Guthrie, who was dancing on a chair by the evening’s end.

Prominent New Yorkers included Gov. Andrew Cuomo and Sandra Lee, Harold Ford Jr. and wife Emily, Police Commissioner Ray Kelly, hedge funder Paul Tudor Jones, Dick Parsons, music moguls Charlie Walk and Russell Simmons, Kyle MacLachlan and Desiree Gruber.

Also there were Patriots owner Bob Kraft, Paramount’s Brad Grey, Bill O’Reilly, Eric Cantor, John Demsey, Tamara Mellon and Mike Ovitz, Harvey Weinstein and Georgina Chapman, John McEnroe and Vivi Nevo.

The event raised more than $3 million for cultural and educational programs at Harlem’s famed Apollo Theater.