McCartney, who has been knighted by the queen of England, is being honored with Washington's highest award for pop music this week by the Library of Congress. The Gershwin Prize for Popular Song is named for the U.S. songwriting brothers George and Ira Gershwin, whose collections are housed at the library.
"Some of the songs you write, you don't know where they come from," McCartney said on stage Tuesday night. "So I have to believe in the magic."
The tune for "Yesterday" came to him in a dream, he said. Nobody could place it, so he claimed it as his own.
McCartney joked the original lyrics were "Scrambled egg. Oh my baby how I love your legs."
Then he took his guitar and said "Here goes nothin," before he sang the familiar tune for a Washington crowd at a private concert at the library. The audience included House Speaker Nancy Pelosi, Stevie Wonder and comedian Jerry Seinfeld. He also sang an encore of "Blackbird."
The 67-year-old McCartney said he's "slightly nervous" about performing about 3 feet in front of President Barack Obama in the East Room at the White House on Wednesday, when he will be presented the award.
"For an English kid growing up in Liverpool, the White House - that's pretty special," he said Tuesday.
"He's a great guy," McCartney said of Obama, "so lay off him."
The former Beatle says it's very special to win the Gershwin Prize because he grew up listening to music by the Gershwin brothers. Wonder and Paul Simon previously won the Gershwin prize.
Librarian of Congress James Billington said McCartney made an impact beyond music, "symbolizing and humanizing the global soundscape," and with his activism around the world.
Faced with the Washington press corps, McCartney was quizzed on his inspiration for songwriting, his opinion on whether performers should earn royalties for when their work is played on the radio (he thinks they should) and even got a few autograph requests.
This is McCartney's first major lifetime achievement award from the U.S. government. He was slated to win a Kennedy Center Honor, the nation's top prize for performing artists, in 2002, but backed out because of a scheduling conflict. In 1990, McCartney won the Grammy Lifetime Achievement Award.
The Jonas Brothers, Faith Hill, Stevie Wonder and Seinfeld are part of an all-star lineup that will honor McCartney at the White House concert. The concert will be televised July 28 nationwide on PBS.
Performers also will include White Stripes singer and guitarist Jack White, Foo Fighters frontman Dave Grohl, singers Emmylou Harris, Elvis Costello and others.
McCartney was knighted as Sir Paul in 1997 for his service to music. Thirty years earlier, he and the rest of the Fab Four were dubbed Members of the Order of the British Empire, a step below knighthood and an honor that drew some protests.
The one-time teen idol has since made his name as an environmentalist and animal rights supporter.
He said the Gulf Coast oil spill is "a disgrace" and those responsible must know how to cap a gusher if they're allowed to drill at the sea floor in the future.
On Tuesday, he performed "Yesterday" with the Loma Mar Quartet, which played string instruments from the library's Stradivari collection dating back to the late 1600s. Pianist Lang Lang also performed on George Gershwin's piano.
Pelosi, went gaga over the former Beatle.
"Congratulations, Sir Paul," Pelosi said. She thanked him for letting Americans travel with him "down the long and winding road," and added "P.S. We love you."