If someone committed a grave sin and is ashamed of himself, what should he do to rectify his position and earn Allah’s forgiveness?

The first thing that we must understand is that Islam acknowledges man’s weakness in the face of temptation, and it accepts man with his weaknesses, opening before him the way to redress his mistakes and repair what he damages. Hence, the relationship between man and Allah is based on forgiveness, rather than permanent sin, disobedience, and eventual punishment. Allah’s attributes make mercy, grace, and forgiveness available in increasing degrees, while punishment is much narrower. Thus God describes Himself as “much-forgiving; superior in forgiveness; forgives all sins, etc.” This is to encourage everyone who commits grave sins not to despair of Allah’s forgiveness because nothing will stop such forgiveness when sought in earnest.

We need also to understand that Allah’s forgiveness applies even to the most serious of sins, including the ones that incur specified punishments of the sternest type, such as theft and adultery. It is also important to make clear that in saying so we do not wish to give a sense of complacency that accepts such sins, or even lighter ones. All sinful actions must be avoided with all one’s energy. Even the smallest of sins is an act of defiance and disobedience to Allah Almighty. As such it cannot be condoned in any way. However, when one slip, yields to temptation, or gets misguided and commits a sin, the way is open to repentance and earning Allah’s forgiveness.

The first thing that is needed is to genuinely regret having committed such an act that incurs Allah’s displeasure. This is what is called in Islam “repentance”, i.e. to feel ashamed of having disobeyed Allah and to want to do anything to redress the fault. This regret should be coupled with a firm resolve not to repeat that sin, no matter how strong the temptation of a repeat may be. One should then earnestly pray to Allah to accept one’s repentance and forgive one’s sin.