This was written by Kris Kristofferson, who has written hundreds of songs for a wide variety of artists. Kristofferson would become a successful solo artist and appear in several movies, but it was Janis Joplin's hit cover of this song that brought his career to the next level. "'Bobby McGee' was the song that made the difference for me," he told Performing Songwriter in 2015. "Every time I sing it, I still think of Janis."
Kris Kristofferson released this in 1970 on his first album, Kristofferson. A year later, when it became a hit for Joplin, Kristofferson's album was re-released as Me And Bobby McGee to take advantage of the song's new popularity.
This was released after Joplin died of a heroin overdose. Her death gave the album a lot of attention, and Pearl went to #1. It was the second song to hit #1 in the US after the artist had died; "Dock Of The Bay" by Otis Redding was the first.

The version on Joplin's 1995 Greatest Hits album 18 Essential Songs contains an alternate version recorded as a demo:
Janis Joplin - Me and Bobby McGee just Janis playing an Acoustic (From the Pearl Session Tapes. Recorded 7-28-70)
Lyrics
Busted flat in Baton Rouge, waiting for a train
I was feeling near as faded as my jeans
Bobby thumbed a diesel down just before it rained
And rode us all the way to New Orleans
I pulled my harpoon out of my dirty red bandana
I was playing soft while Bobby sang the blues
Windshield wipers slapping time, I was holding Bobby's hand in mine
We sang every song that driver knew
Freedom's just another word for nothing left to lose
Nothing don't mean nothing honey if it ain't free, now now
And feeling good was easy Lord, when he sang the blues
You know feeling good was good enough for me
Good enough for me and my Bobby McGee
From the Kentucky coal mines to the California sun
Hey, Bobby shared the secrets of my soul
Through all kinds of weather, through everything that we done
Hey Bobby baby kept me from the cold
One day up near Salinas, Lord, I let him slip away
He's looking for that home and I hope he finds it
But I'd trade all of my tomorrows for one single yesterday
To be holding Bobby's body next to mine
Freedom's just another word for nothing left to lose
Nothing, and that's all that Bobby left me, yeah
And feeling good was easy Lord, when he sang the blues
Hey, feeling good was good enough for me, hmm hmm
Good enough for me and my Bobby McGee
La la la, la la la la, la la la, la la la la
La la la la la Bobby McGee
La la la la la, la la la la la
La la la la la, Bobby McGee, la
La La la, la la la la la la
La La la la la la la la la, hey now Bobby now Bobby McGee yeah
Na na na na na na na na, na na na na na na na na na na na
Hey now Bobby now, Bobby McGee, yeah
Lord, I called him my lover, I called him my man
I said called him my lover just the best I can and come on
And and a Bobby oh, and a Bobby McGee yeah
Lo lo lo lo lo lo lo lo lo lo lo lo
Hey hey hey Bobby McGee, lord
La da la la la, la da la la la la la
Hey hey hey, Bobby McGee yeah