David, the king of Israel, wrote Psalm 51 after he had committed adultery with Bathsheba and murdered her husband (2 Samuel 11). He wrote it after he was confronted by the prophet Nathan, and confessed, "I have sinned against the Lord" (2 Samuel 12:13).
Psalm 51 is the humble, sincere prayer of a sinner who is sorry for his sins; someone who is looking forward to God's forgiveness and restoration. David asks God to "create" for him a "pure heart" - which only God can do. He realized that he had sinned because he was not steadfast enough - he was swayed by temptation and his own devious desire. He is also afraid that God will cast him away from God's presence; deprive him of the Holy Spirit and God's help. It is a fervent prayer realizing how much he will lose without God's "mercy… unfailing love…and ''great compassion" (v 1).
In humility, David asked for a spirit of fervour to sustain him (v 12) - God's spirit that will not only "sustain" him, but will strengthen him to teach transgressors God's ways and help sinners return to God (v 13).
Are your spirit and heart, broken, because of your sin(s)? God will never turn away from anyone (in their brokenness) who goes before God in humility. What would you say to God in your repentance?
"A humbled, contrite heart You will not spurn" (Ps. 51: v 17)