“Amazing Grace” is a hymn that’s recognizable to almost every American, regardless of religious background.

“It seems kind of like an all-purpose, hopeful song,” says Steve Turner, author of “Amazing Grace: The Story of America's Most Beloved Song.” But while the song has a universal message, its origins are much more complex.

For one, while the song is a well-known anthem of the civil rights movement, its original text was written by a former slave trader. John Newton was an Anglican priest in England in 1773, when he debuted a hymn to his congregation called “Faith’s Review and Expectation.”

The hymn opened with a powerful line: “Amazing grace! (how sweet the sound) That sav’d a wretch like me!” And it drew on Newton’s own experience as a slave trader — specifically, from a near-death experience he’d had decades earlier, when the slave ship he was on encountered a violent storm, prompting him to convert to Christianity. (Newton didn’t speak out against slavery until 1788.)

The hymn wasn’t particularly popular in England, according to Deborah Carlton Loftis, executive director of the Hymn Society in the United States and Canada. But she says in the United States, it became well-known during the Second Great Awakening in the early 1800s when thousands of people — white and black — would gather for outdoor revival meetings.

Songs were important to these meetings — although not always exactly as they were written. Revival leaders frequently switched out melodies and borrowed verses from other hymns. “There were choruses and refrains that people could learn quickly,” Loftis says.

Reverend Matthew J. Watts, the pastor of the Grace Bible Church in Charleston, West Virginia, says that for slaves, a song like “Amazing Grace” would have been particularly meaningful.

"'Amazing Grace' would have spoke to their desire for an experience of freedom, of one day seeing God face-to-face, of one day being with him for all of eternity, and no longer subjected to the type of cruel treatment they experienced during slavery," he says.

Music scholars think that “Amazing Grace” was sung at revivals to many different tunes, but the one we recognize today is a melody called “New Britain,” first published with the “Amazing Grace” lyrics in 1847. And in 1852, when Harriet Beecher Stowe wrote the song into “Uncle Tom’s Cabin,” she included a few verses that weren’t in Newton’s original text — such as the one beginning, “When we’ve been there ten thousand years, Bright shining like the sun.” We may have revivals to thank for those verses, according to producer Trey Kay.

“Author Harriet Beecher Stowe was the daughter and sister of revival preachers, and she may have heard 'Amazing Grace' sung this way at a revival meeting,” he says. “Some think her novel may have played a role in shaping how we sing ‘Amazing Grace’ today.”

In the 20th century, the song became a staple for gospel and folk artists. First recorded by the Original Sacred Harp Choir in 1922, it was soon eternalized by other singers like Sister Rosetta Tharpe, Reverend J.M. Gates and Aunt Molly Jackson. And during the civil rights movement, Kay says, activist Fannie Lou Hamer led protesters in singing “Amazing Grace,” helping to define racial equality as a moral and religious pursuit.

One of the song’s most famous versions is by Judy Collins, who remembers attending an encounter group (to help people share their true feelings) in 1969 that grew heated. Her record producer, who was also there, asked her to sing something.

“My grandmother was a churchgoing Methodist, and she had taught me 'Amazing Grace' when I was a little girl,” Collins said. “It was one of the few songs that I knew that I figured everybody would know something of, and they all sang. And it did settle everybody down.” She recorded the song the next day, on her producer’s suggestion, and it became a hit. Her version even became famous on British radio, inspiring a bagpipe arrangement by the Royal Scots Dragoon Guards.

Since then, the bagpipe rendition of “Amazing Grace” has come back stateside — as a beloved part of memorials for public servants like police, firefighters and the military.

From her home on New York’s Upper West Side, Collins can sometimes hear bagpipers playing “Amazing Grace” at the Firemen’s Monument. “It's an amazing thing, it's very moving,” she says. And in 2015, after the Reverend Clementa Pinckney and eight others were shot and killed at Emanuel African Methodist Episcopal Church in Charleston, South Carolina, President Barack Obama closed his eulogy for Pinckney with a few stanzas of the song.

James Basker, an English historian at Barnard College, has an idea of why the song’s music and lyrics have such appeal at moments of deep human suffering. “They appeal without any narrowness,” he says. “There is no specific condition, there's no specific religious faith, there's no specific cultural context.”

“It's just about that thing that human beings share, which is pain, and the imaginative yearning. And this is the thing about human beings. We are able to imagine, and to yearn for, joy and peace — for relief from the miseries of this world.”

This article is based on a story produced by Trey Kay that aired on PRI's Studio 360 with Kurt Andersen. Kay hosts the podcast Us & Them.