Psalm 31:1-5: "1 In you, O LORD, do I take refuge; let me never be put to shame; in your righteousness deliver me! 2 Incline your ear to me; rescue me speedily! Be a rock of refuge for me, a strong fortress to save me!
"3 For you are my rock and my fortress; and for your name's sake you lead me and guide me; 4 you take me out of the net they have hidden for me, for you are my refuge. 5 Into your hand I commit my spirit; you have redeemed me, O LORD, faithful God."
Psalm 40:4: "Blessed is the man who makes the LORD his trust, who does not turn to the proud, to those who go astray after a lie!"
Psalm 64:10: "Let the righteous one rejoice in the LORD and take refuge in him! Let all the upright in heart exult!"
+++
The text is public domain:
1 I trust, O Lord, Your holy name;O let me not be put to shameNor let me be confounded.My faith, O Lord,Be in Your WordForever firmly grounded.2 Bow down Your gracious ear to meAnd hear my cry, my prayer, my please;Make haste for my protection,For woes and fearSurround me here.Help me in my affliction.3 You are my strength, my shield, my rock,My fortress that withstands each shock,My help, my life, my tower,My battle sword,Almighty Lord -Who can resist Your power?4 With You, O Lord, I cast my lot;O faithful God, forsake me not,To You my soul commending.Lord, be my stay,And lead the wayNow and when life is ending.5 All honor, praise, and majestyTo Father, Son, and Spirit be,Our God forever glorious,In whose rich graceWe run our raceTill we depart victorious.
+++
The passage from Psalm 31 is the main source for the hymn. Psalm 31:1 is paraphrased in the first two lines, and Psalm 40:4 is also incorporated. "Incline your ear to me" from Psalm 31:2 is rendered as "Bow down Your gracious ear to me" at the beginning of the hymn's second verse. The description of God as a refuge in Psalm 31:2-4 and Psalm 64:10 appears in the hymn's third verse, although other Biblical passages could be cited here, too, such as Psalm 28:7 ("The LORD is my strength and my shield; in him my heart trusts, and I am helped; my heart exults, and with my song I give thanks to him.") and Proverbs 18:10 ("The name of the LORD is a strong tower; the righteous man runs into it and is safe."). "Into your hand I commit my spirit" from Psalm 31:5 appears in the fourth verse: "With You, O Lord, I cast my lot... To You my soul commending."
The lines "In whose rich grace / We run our race / Till we depart victorious" at the end of the fifth verse seem to allude to part of Hebrews 12:1: "let us run with endurance the race that is set before us."