The melody was composed as part of NIelsen's contribution to Nye Melodier til Johan Borups Sangbog. The idea of setting music to the text apparently came from Adolf Riis-Magnussen, the editor of the songbook, who ended up appreciating the melody. According to a letter to his family, Nielsen was very satisfied with it, too. See more about this work at The Royal Library