Paul McCartney wrote a song just for Michael Jackson. It took the long way to reach him.

“You know, I’ve written a song for you.”

That’s what Paul McCartney told a 17-year-old Michael Jackson when they shook hands at a crowded party in Beverly Hills. It was June 1976. Paul had just finished a big tour of America with his band Wings, and the party was their way of celebrating the end of it.

Michael already loved the Beatles. Now one of them was standing in front of him saying he’d written a song with Michael in mind.

“I was very surprised and thanked him,” Michael remembered in his 1988 book, “Moonwalk.” Then Paul did something even better. Right there in the middle of the party, he started singing it to him.

The song was called “Girlfriend,” a light, bouncy love song. Paul reportedly said later that he’d always thought of it as something he might give to the Jackson 5 one day.

The two of them swapped phone numbers that night and promised to get together soon.

You can probably guess what happened next. It’s the same thing that happens to most of us after a good party. “Different projects and life just got in the way for both of us,” Michael wrote, “and we didn’t talk again for a couple of years.”

Paul didn’t sit on the song. In February 1977 he took it into the studio in London and recorded it with Wings. It came out in March 1978 on their album “London Town.” Paul sings the lead himself, with his wife Linda and bandmate Denny Laine behind him.

Paul and Wings sing “Girlfriend” first

So that seemed to be that. The song Paul had written for Michael now belonged to Paul.

But Michael was about to make the most important album of his young life. He was 20 and going solo, with a new producer working beside him: Quincy Jones. They were hunting for songs.

And somehow “Girlfriend” turned up again.

Michael recorded it for “Off the Wall,” which came out in August 1979. His version skips a whole middle section that Paul’s version has. Listen to how the same song changes when Michael sings it.

Michael’s own version from “Off the Wall”

Here’s the twist.

The song didn’t come back to him through Paul. It came back through Quincy. After “London Town” came out, Quincy heard “Girlfriend” and suggested it for Michael’s new album. He reportedly had no idea that Paul had already sung it to Michael at that party three years earlier.

“Girlfriend” went on to be the last single from “Off the Wall,” released in Britain in 1980. And Michael and Paul did finally get together, just as they’d promised. They went on to sing “The Girl Is Mine” and “Say Say Say” as a duo.