The words to this hymn were written by British actress, dramatic poet and Unitarian hymn writer Sarah Flower Adams (1805-1848) at her home in Sunnybank, Loughton, Essex, England, in 1841. She based them loosely on Genesis 28:11–19, the story of Jacob's dream, when he saw a ladder perched on the earth going up to heaven with angels climbing up and down it. At the top of the ladder stood God, and he reiterated the promise he made to Jacob's grandfather Abraham that he will have numerous descendants who will live in the land that he had promised to them.
In the United Kingdom, the hymn is usually sung to the 1861 hymn tune "Horbury" by John Bacchus Dykes, while in the rest of the world, it is usually associated with the 1856 tune "Bethany" by Lowell Mason.
The story goes that when the American president, William McKinley was assassinated in 1901, he whispered the words of his favorite hymn "Nearer, my God, to thee, nearer to thee, e'en though it be a cross that raiseth me," as he lay dying. McKinley told the attending doctor "This has been my constant prayer." At 3:30 pm, in the afternoon of September 14, 1901, after five minutes of silence across the nation, numerous bands across the United States played McKinley's favorite hymn, in his memory.
The hymn is most famous as the alleged last song the band on RMS Titanic played before the ship sank. The "Bethany" version was used in the 1943, 1953 and 1995 films about the disaster, all titled Titanic, whereas the "Horbury" version was played in A Night to Remember, Roy Ward Baker's 1958 movie about the sinking.
The hymn featured in the famous Brides in the Bath murder case in which Bristol antique dealer George Joseph Smith was convicted in 1915 of murdering three wives in succession by drowning them in the bath. While the body of one bride was still in the bath Smith went down into the sitting room and played 'Nearer, my God, to Thee' on the harmonium.