According to Don Henley, the song was based on something he wrote in 1968 with a different title, but the same melody and chords. In 1972, about a day or two after they returned from London where they recorded their first album Eagles, Glenn Frey went to his place to write songs. Henley played him his unfinished tune and said: "When I play it and sing it, I think of Ray Charles — Ray Charles and Stephen Foster. It’s really a Southern gothic thing, but we can easily make it more Western." The song Henley played had lyrics about a friend of his named Leo, which began "Leo, my God, why don’t you come to your senses, You’ve been out ridin' fences for so long now." Jackson Browne had suggested a Western theme for the song, and Frey then helped with the lyrics and gave it structure, and the song became "Desperado". Henley said of the writing of "Desperado" with Frey: "And that was the beginning of our songwriting partnership ... that’s when we became a team."
The song was recorded at Island Studios in London, with musicians from the London Philharmonic Orchestra conducted by Jim Ed Norman, Henley's friend from his early band Shiloh, who wrote and arranged the strings for the song. Henley sang the lead vocal on the song, but would later express regret that he did not sing as well as he could. Henley said of the recording: "I was so intimidated that I didn't sing my best. Our producer Glyn Johns, who is still a friend of mine, I think, wanted to get the album done quickly and economically, and he didn't let me do many takes. I wish I could have done that song again."
"Desperado" was ranked No. 494 on Rolling Stone's 2004 list of "The 500 Greatest Songs of All Time". although it was moved out of Top 500 in the 2010 revision of the list after newer songs were added to the list. The song never charted on Billboard until the death of Glenn Frey when it reached No. 20 on the Rock Digital Songs chart.