The words appear in 1700 by Nahum Tate. The tune is called Winchester Old appearing first in 1592. According to wikipedia "The tune and hymn text were probably first published together in an arrangement by William Henry Monk for Hymns Ancient and Modern in 1861"