And so it came to pass that Abraham [previously Abram] and Sarah packed up and did some travelling. They dwelled for a while between Kadesh and Shur and then journeyed to Gerar.
They decided to settle down in Gerar for a while.
When they got there they lied to the king of Gerar ... Abimelech. As with the Egyptian Pharaoh they again said that Sarah was Abraham's sister, and not his wife. Abraham was scared that he would be killed because of Sarah.
Then one night God appeared before Abimelech in a dream, and He said to Abimelech: 'You are going to die if you marry this woman. She is already married.'
Abimelech was scared and he asked The Lord if He would destroy an innocent nation because of her. He told The Lord that Abraham and Sarah told him that Sarah was only Abraham's sister, that he, Abimelech no way could have known what the truth was. And he felt deeply relieved that he didn't have intercourse with her.
The Lord answered him that He knew what was going on, and that was the reason why God is warning him now, before anything got worse. God then ordered him to give Sarah back to Abraham the prophet, ... or else he would die. Sarah was important to God, because of the important child that He had planned for her.
The next morning Abimelech gathered his men and told them the story and they were as much afraid as he was.
Abimelech called Abraham and asked him why he told such a terrible lie. And Abraham told him that he did it because he was afraid for his life, if anybody would know that he was Sarah's husband and not her brother.
Abimelech then decided to get rid of them as soon as possible. So he took sheep, oxen and servants and gave them to Abraham, as well as Sarah. He invited Abraham and Sarah to live anywhere on his land that they wish to. He also gave Abraham a 1000 pieces of silver to keep Sarah quiet about what happened.
God rewarded Abimelech by healing him and his wife, and his slaves ... so that they could have children again. God had closed up all the wombs of the house of Abimelech ... because of Sarah the wife of Abraham.
Abraham and Sarah went to live in the plains of Gerar.
Source: The Bible: Genesis 20