This song was written by the prolific songwriting team of Burt Bacharach and Hal David. When they wrote this, they were not full-time partners yet but were considering doing so.
Many people think that this is the theme song for the 1962 movie of the same name. Although it was written for the movie and everybody loved it, John Ford (the movie's director) hated it and kept it off the soundtrack. Gene Pitney himself later said: "The song 'Liberty Valance' was written for the movie but for some strange reason never was put in the soundtrack. Because of the prior success with 'Town Without Pity,' I was paid a bundle to record the song, and Burt Bacharach produced it. He wrote the song with Hal David. There was some screw-up between the publishing company, Famous Music, and the parent company, Paramount Pictures. As to why it never was in the actual film, the most bizarre part of the story I found out a few years ago. The actual music used in the film was from a 1938 Henry Fonda film called Young Mr. Lincoln. Go figure that out!"
Suggestion credit: Jerro - New Alexandria, PA, for above 2