Charles Wesley had a history of encouraging people to pray for the salvation of a variety of people. He wrote "Sun of Unclouded Righteousness" with the subtitle of "For the Turks" or "For the Mahometans". It was first published in 1758 in his Hymns of Intercession for All Mankind hymnal. It was intended as a prayer for salvation of Muslims and reflected the prevalent negative view of Islam promoted by Humphrey Prideaux in Great Britain at the time. It was written to also accompany the Collect for Good Friday in the Church of England's Book of Common Prayer. The hymn's title was based upon Malachi 4:2 where the Messiah, believed to be referring to Jesus by Christians, was called the "Sun of Righteousness".
Charles and his brother John Wesley had read Prideaux's work on early Islam while in Paris, and John noted that no opponents of Christianity had hurt it as much as Muhammad during the Early Muslim conquests. The hymn refers to that conquest in the line, "The smoke of the infernal cave,/Which half the Christian world o’erspread"; the "cave" mentioned there is Hira, where Islam teaches that Mohammed received revelation. Muhammad is referred to in the hymn as "that Imposter" and "that Arab Thief". Later versions of the third verse were changed to "E'en now the Moslem fiend expel, And chase his doctrine back to hell".
The hymn also engaged in polemics with regard to theological controversies of its day, namely the conflict between John Taylor's Unitarianism and Christians who held a trinitarian universalism perspective. The fourth stanza had always expressed the trinitarian universalism perspective; earlier versions of the third stanza ended with "The Unitarian fiend expel/And chase his doctrine back to hell" referring to Islam and its teaching, but also more explicitly to this controversy. The hymn was, in the words of a commenter on it, "an implicit challenge" to send missions to those regions.