Longfellow wrote the poem shortly after completing lectures on German writer Johann Wolfgang von Goethe and was heavily inspired by him. He was also inspired to write it by a heartfelt conversation he had with friend and fellow professor at Harvard University Cornelius Conway Felton; the two had spent an evening "talking of matters, which lie near one's soul:–and how to bear one's self doughtily in Life's battle: and make the best of things". The next day, he wrote "A Psalm of Life". Longfellow was further inspired by the death of his first wife, Mary Storer Potter, and attempted to convince himself to have "a heart for any fate".
The poem was first published in the October 1838 issue of The Knickerbocker, though it was attributed only to "L." Longfellow was promised five dollars for its publication, though he never received payment. This original publication also included a slightly altered quote from Richard Crashaw as an epigram: "Life that shall send / A challenge to its end, / And when it comes, say, 'Welcome, friend.'" "A Psalm of Life" and other early poems by Longfellow, including "The Village Blacksmith" and "The Wreck of the Hesperus", were collected and published as Voices of the Night in 1839. This volume sold for 75 cents and, by 1842, had gone into six editions.
In the summer of 1838, Longfellow wrote "The Light of Stars", a poem which he called "A Second Psalm of Life". His 1839 poem inspired by the death of his wife, "Footsteps of Angels", was similarly referred to as "Voices of the Night: A Third Psalm of Life". Another poem published in Voices of the Night titled "The Reaper and the Flowers" was originally subtitled "A Psalm of Death".