Washington (CNN) -- A long and winding road brought Sir Paul McCartney to the White House on Wednesday, where he was honored by the president of the United States and performed some of the most famous songs from his catalogue with the Beatles and after.

President Barack Obama awarded McCartney the Library of Congress Gershwin Prize for Popular Song and then, along with a little help from some of his friends, such as Stevie Wonder, Faith Hill, Elvis Costello, Emmylou Harris and others, McCartney rocked the East Room of the White House.

Obama noted McCartney had been involved in writing more than 200 songs that had made the charts of bestsellers, and his songs had stayed on those charts for a cumulative total of over 32 years. McCartney shook his head in wonder at that fact.

"Nearly half a century since four lads from Liverpool first landed on our shores and changed everything overnight," Obama said, noting that the bass McCartney played Wednesday was the same one from when the Beatles performed on TV's Ed Sullivan Show in the 1960s.

The Gershwin Prize, America's highest award for popular music, was bestowed on behalf of a grateful nation, "grateful that a young Englishman shared his dream with us," Obama said.

McCartney thanked Obama for the honor and, in a short political comment, said that he and "billions" of others supported what the president was doing in the face of many challenges. Later, McCartney ended the night by saying, in reference to the prize from the Library of Congress, it was good that after the last eight years, America had a president who knew what a library was.

The music for the event, which was taped for a PBS special, included unique and riveting versions of well-known songs by a variety of artists. Wonder performed "We Can Work Out It Out," starting over at one point when he couldn't find his harmonica. Costello sang "Penny Lane", noting his mother grew up near the location of the song, while Harris sang "For No One," noting it was "the sad song."

McCartney performed the duet "Ebony and Ivory" with Wonder, and then ended the event with some of the most popular songs of his career, including the love ballad "Michelle" in honor of the first lady, who attended with both first daughters and the first grandmother. McCartney quipped that, given the song's title, he might be the first guest to get punched out by the president.

He followed that with "Eleanor Rigby," "Let It Be" and a rousing "Hey Jude" that concluded with the first family and all the performers on stage, singing along to the well-known refrain of the title.

On Tuesday, McCartney toured the Library of Congress, rehearsed for Wednesday's concert and held a news conference with reporters. They asked the former Beatle about everything from performance royalties and the role of songwriters today to the oil spill in the Gulf of Mexico.

McCartney noted that he is not a politician, but said the Gulf of Mexico oil spill is a disgrace.

"I think the fact that something like that can happen and the people who are to blame don't have the ability to instantly cap it and clean it up is something that's going to be addressed," he said.

Obama mentioned the oil spill in his remarks Wednesday, saying the nation shared in the sorrow of people from the Gulf coast region that also has a rich musical heritage.

He noted that people on the Gulf Coast were "dealing with something we have not seen before," and called the situation "heartbreaking." The president pledged the nation's commitment "to see to it that their lives and their community are made whole again."

CNN's Tom Cohen contributed to this report