LOS ANGELES -- Apparently, it's never too late to perform at the Oscars, particularly if you're an Oscar winner named Eminem.

The rapper shocked the crowd at the Dolby Theatre and viewers at home on Sunday night with his performance of "Lose Yourself" -- 17 years after it won best original song from the movie "8 Mile."

"Look, if you had another shot, another opportunity... Thanks for having me @TheAcademy. Sorry it took me 18 years to get here," tweeted the rapper, whose real name is Marshall Mathers.

His math was a bit off, though. Barbra Streisand announced "Lose Yourself" as the Oscar winner in 2003. Mathers didn't attend the ceremony to collect his trophy as the songwriter.

Lin-Manuel Miranda introduced a package of clips showing off the use of pop music in films before a bearded Eminem rose from beneath the stage to perform.

It was one of the most exhilarating moments of the evening. Grammy-winner Billie Eilish, set to perform on the show later, dropped her jaw. Several other audience members were shown rapping along or bobbing to the beat in their seats, including actresses Zazie Beetz and Kelly Marie Tran and musician-actress Janelle Monae, who opened the show.

Director Martin Scorsese wasn't one of them. He appeared to briefly close his eyes when the cameras found him in the crowd.

Backstage producer Lynette Howell Taylor was especially excited, save for a momentary panic that he didn't have his mic. Afterwards she squealed "We did it! We (expletive) did it."

The rapper got a standing ovation when he finished.

------

AP Film Writer Lindsey Bahr contributed to this report.