Matthew 27:45-50: "45 Now from the sixth hour there was darkness over all the land until the ninth hour. 46 And about the ninth hour Jesus cried out with a loud voice, saying, 'Eli, Eli, lema sabachthani?' that is, 'My God, my God, why have you forsaken me?' 47 And some of the bystanders, hearing it, said, 'This man is calling Elijah.' 48 And one of them at once ran and took a sponge, filled it with sour wine, and put it on a reed and gave it to him to drink. 49 But the others said, 'Wait, let us see whether Elijah will come to save him.' 50 And Jesus cried out again with a loud voice and yielded up his spirit."
Romans 5:6-12: "6 For while we were still weak, at the right time Christ died for the ungodly. 7 For one will scarcely die for a righteous person - though perhaps for a good person one would dare even to die - 8 but God shows his love for us in that while we were still sinners, Christ died for us. 9 Since, therefore, we have now been justified by his blood, much more shall we be saved by him from the wrath of God. 10 For if while we were enemies we were reconciled to God by the death of his Son, much more, now that we are reconciled, shall we be saved by his life. 11 More than that, we also rejoice in God through our Lord Jesus Christ, through whom we have now received reconciliation.
"12 Therefore, just as sin came into the world through one man, and death through sin, and so death spread to all men because all sinned..."
Romans 12:1: "I appeal to you therefore, brothers, by the mercies of God, to present your bodies as a living sacrifice, holy and acceptable to God, which is your spiritual worship."
1 Peter 2:24: "He himself bore our sins in his body on the tree, that we might die to sin and live to righteousness. By his wounds you have been healed."
+++
The text is public domain:
Alas! And did my Savior bleed,
And did my sov'reign die?
Would He devote that sacred head
For such a worm as I?
Was it for crimes that I had done
He groaned upon the tree?
Amazing pity, grace unknown,
And love beyond degree!
Well might the sun in darkness hide
And shut his glories in
When God, the mighty maker, died
For His own creatures' sin.
Thus might I hide my blushing face
While His dear cross appears,
Dissolve my heart in thankfulness,
And melt mine eyes to tears.
But drops of grief can ne'er repay
The debt of love I owe;
Here, Lord, I give myself away:
'Tis all that I can do.
+++
Matthew 27:45-50 is the main referent. Verse 50 is rendered as "He groaned upon the tree" in the second verse, and the darkness mentioned in verse 45 appears as "Well might the sun in darkness hide..." in the third verse.
Romans 5:6-12 is the basis for the questions in the first verse, and - in the same way - 1 Peter 2:24 is behind the question "Was it for crimes that I had done / He groaned upon the tree?" in the second verse.
"Present[ing] your bodies as a living sacrifice" from Romans 12:1 appears at the end of the hymn, in the line "Here, Lord, I give myself away."