Wearing jeans and a black T-shirt, Garcetti played on Moby’s song “The Perfect Life,” and at one point launched into a keyboard solo.

Moby introduced Garcetti as “the next president of the United States.”

“What you may not know,” Moby told the crowd, “is that Mayor Garcetti is an excellent keyboardist.”

Moby is currently doing a three-night gig at The Fonda for his new album, Innocents.

Garcetti’s appearance was a surprise to the hundreds of fans in the audience, who gave the 42-year-old mayor a rowdy round of applause as he left the stage. Some also posted photos and videos on Instagram and Twitter. Wrote Twitter user MikeySops: “Mayor Garcetti just rocked the keyboard at the Moby show like a boss.”

Moby played at Garcetti’s inauguration at City Hall this summer, and performed at fundraisers during his race for mayor.

Garcetti has played piano since age 5, said mayoral spokeswoman Vicki Curry. She said he learned the chords to “The Perfect Life” the day before the show, and improvised the rest of the song.