The words to Amazing Grace were first published in 1779, written by a minister named John Newton. While it doesn't seem surprising that a man of the cloth would write a piece about God's salvation, the story behind the words and the man is more complex than you would think.
John Newton was born in 1725. His mother was religious, but his father commanded a merchant ship and young John was sailing with him by age 11. In 1744, John was impressed into the British Navy, which means he was taken forcibly and made to join. Another term for it was press-ganging, and it was a common means of gaining military recruits in eighteenth-century Britain. But Newton was obstinate and headstrong and at one point tried to desert, for which he was demoted as punishment.
Newton ended up in service on a slave ship off the African coast. Again his temper and mouth got him into trouble, and he ended up being restrained and starved for his behavior by a tyrannical slave trader (his boss!). He was eventually rescued, and by 1748, was captaining his own ship in the slave trade. All of this, by the way, happened before he was 23 years old.
It would seem his life's pattern had been set. Sailors had little time for religion, with long hours, backbreaking work in confined quarters, and months at sea. Plenty of salty language came with the life, and Newton was known for his profanity.
But, in 1748, he began to change. His ship, the Greyhound, became caught in a terrible storm, and he spent time lashed to the deck to keep from being swept overboard. It shook him and awakened a newfound sense of humility. He briefly continued in the slave trade, but illness forced him on land permanently by the time he was 30.
A sense of service began to grow in him, and Newton studied to become a minister. In 1764, he was ordained in the Church of England. He eventually came to renounce the slave trade, and later became an ardent abolitionist, someone who fought publicly to end the slavery.
Newton accepted a position as a church curate in Olney in Buckingshire, England. The poet William Cowper moved to Olney a few years later, and the two began collaborating on a book of poems to be used in church services. At the time, hymns didn't have specific music connected to them the way they do today. The words to Amazing Grace first appeared in 1779, in an edition of poems published in Olney. It could be sung to any tune fitting the meter (cadence or pacing of the words).