Genesis 20 provides an account of Abraham's sojourn in Gerar.
Abraham moved to the region of Gerar, where he told people that his wife Sarah was his sister (similar to his earlier deception in Egypt). King Abimelech of Gerar took Sarah into his harem, not knowing she was already married.
God appeared to Abimelech in a dream, warning him that Sarah was a married woman and that he was as good as dead for taking her. Abimelech, who had not yet approached Sarah, protested his innocence to God, saying he acted with a clear conscience since Abraham claimed she was his sister. God acknowledged Abimelech's innocence but instructed him to return Sarah to Abraham, who was a prophet who would pray for him.
Abimelech confronted Abraham about the deception. Abraham explained he feared for his life because he thought there was no fear of God in Gerar — and technically Sarah was his half-sister. Abimelech gave Abraham livestock, servants, and silver as compensation, and he invited him to live in his land wherever he pleased.
Abraham prayed to God, and God healed Abimelech, his wife, and female servants so they could bear children again (God had closed all the wombs in Abimelech's household because of Sarah).