South of Israel and roughly half way between Beersheba and Gaza, is the town of Gerar. In the time of Abraham, it was ruled by a Philistine king named Abimelech. By a strange quirk of fate, both Abraham and his son Isaac made treaties with him, after separate incidents in which they presented their respective wives to him as their sisters.
It was soon after the destruction of Sodom, that Abraham went to stay in Gerar.
Now Abraham moved on from there into the region of the Negev and lived between Kadesh and Shur. For a while he stayed in Gerar, and there Abraham said of his wife Sarah, "She is my sister." Then Abimelech king of Gerar sent for Sarah and took her. (Genesis 20:1-2)
God, however, was there to protect Sarah from the consequences of her husband's lack of faith.
But God came to Abimelech in a dream one night and said to him, "You are as good as dead because of the woman you have taken; she is a married woman." (Genesis 20:3)
Abimelec protested that he hadn't known that Sarah was married; in any event he hadn't gone near her. God told him he had nothing to fear if he continued to stay away from her.
The following morning, after rebuking Abraham for the deception he had practiced, Abimelec gave him and Sarah valuable gifts and offered them a settlement in any part of his country. A few years later Abimelech visited Abraham, who had removed southward beyond his territory, and there entered into a league of peace and friendship with him, which was confirmed by a mutual oath at Beersheba.
After Isaac was married, history repeated itself in the oddest fashion. A famine took him and his wife Rebekah to Gerar. When the men of the city asked him who Rebekah was, Isaach told them that she was his sister, afraid that they might kill him to possess her if they thought she was his wife.
A few days after they had stayed there, Abimelech caught Isaac caressing Rebekah, and summoning him found out the truth. Undoubtedly recollecting the earlier warning he had received from God about Sarah, he scolded Isaac.
Then Abimelech said, "What is this you have done to us? One of the men might well have slept with your wife, and you would have brought guilt upon us." (Genesis 26:10)
He gave orders for his men not to harm either of them after which he told Isaac he was welcome to stay in the town. Isaac prospered and it wasn't long before the Philistines began to envy him. Abimelech was also alarmed by his prosperity and growing power and told him to move on, though later, when Isaac was encamped at Beersheba, he visited him and the two made a peace treaty.