From Rolling Stone:
The song was originally intended for Billy Preston, who had a minor hit with it in early 1970, in his album Encouraging Words. It was written in December 1969, when Harrison and Billy Preston were in Copenhagen, Denmark.
…”My Sweet Lord” has a quasi-religious feel, but nevertheless has enough conventional pop appeal to reach mainstream listeners who may or may not care to dig into the spiritual lyrical message. And like much of Harrison’s material from this period, it has an incantational feel, struck by the insistent, mantra-like repetition of the title, echoed by the responsive harmony vocals. The title hook is quite catchy, however, as is the verse, with the sort of subtly ascending key changes that Harrison had mastered on “Something.” The entire song rises to a higher key near the end for the extended fadeout, as if to mimic prayers rising to the heavens. Other principal hooks, of course, are Harrison’s inimitably swooping slide guitar riffs, which recur throughout the piece. Although he has often been criticized for the piety of his lyrical outlook, Harrison delivers the vocal with a winning earnestness that invites listeners to share his joy, rather than making them feel excluded if they don’t happen to subscribe to his particular world view, religious or otherwise.