Abimelech, the king of the Philistines, lived in the city of Gerar and he reigned as king for a long time.
Abimelech was a righteous king.
Isaac stayed around the area of Gerar for a long time and would have meet King Abimelech many times.
Abimelech in Hebrew means: Father of the King.
Isaac and Abimelech
26Now there was a famine in the land—besides the earlier famine of Abraham's time—and Isaac went to Abimelech king of the Philistines in Gerar. 2 The LORD appeared to Isaac and said, "Do not go down to Egypt; live in the land where I tell you to live. 3Stay in this land for a while, and I will be with you and will bless you. For to you and your descendants I will give all these lands and will confirm the oath I swore to your father Abraham.4 I will make your descendants as numerous as the stars in the sky and will give them all these lands, and through your offspring all nations on earth will be blessed,5 because Abraham obeyed me and kept my requirements, my commands, my decrees and my laws." 6So Isaac stayed in Gerar.
7 When the men of that place asked him about his wife, he said, "She is my sister," because he was afraid to say, "She is my wife." He thought, "The men of this place might kill me on account of Rebekah, because she is beautiful."
8 When Isaac had been there a long time, Abimelech king of the Philistines looked down from a window and saw Isaac caressing his wife Rebekah. 9 So Abimelech summoned Isaac and said, "She is really your wife! Why did you say, 'She is my sister'?"
Isaac answered him, "Because I thought I might lose my life on account of her."
10 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."
11 So Abimelech gave orders to all the people: "Anyone who molests this man or his wife shall surely be put to death."
12 Isaac planted crops in that land and the same year reaped a hundredfold, because the LORD blessed him. 13 The man became rich, and his wealth continued to grow until he became very wealthy. 14 He had so many flocks and herds and servants that the Philistines envied him. 15 So all the wells that his father's servants had dug in the time of his father Abraham, the Philistines stopped up, filling them with earth.
16 Then Abimelech said to Isaac, "Move away from us; you have become too powerful for us."
17 So Isaac moved away from there and encamped in the Valley of Gerar and settled there. 18 Isaac reopened the wells that had been dug in the time of his father Abraham, which the Philistines had stopped up after Abraham died, and he gave them the same names his father had given them.
19 Isaac's servants dug in the valley and discovered a well of fresh water there. 20 But the herdsmen of Gerar quarreled with Isaac's herdsmen and said, "The water is ours!" So he named the well Esek, because they disputed with him. 21Then they dug another well, but they quarreled over that one also; so he named it Sitnah. 22 He moved on from there and dug another well, and no one quarreled over it. He named it Rehoboth, saying, "Now the LORD has given us room and we will flourish in the land."
23 From there he went up to Beersheba. 24That night the LORD appeared to him and said, "I am the God of your father Abraham. Do not be afraid, for I am with you; I will bless you and will increase the number of your descendants for the sake of my servant Abraham."
25 Isaac built an altar there and called on the name of the LORD. There he pitched his tent, and there his servants dug a well.
26 Meanwhile, Abimelech had come to him from Gerar, with Ahuzzath his personal adviser and Phicol the commander of his forces.27Isaac asked them, "Why have you come to me, since you were hostile to me and sent me away?"
28 They answered, "We saw clearly that the LORD was with you; so we said, 'There ought to be a sworn agreement between us'—between us and you. Let us make a treaty with you 29 that you will do us no harm, just as we did not molest you but always treated you well and sent you away in peace. And now you are blessed by the LORD."
30 Isaac then made a feast for them, and they ate and drank. 31 Early the next morning the men swore an oath to each other. Then Isaac sent them on their way, and they left him in peace.
32 That day Isaac's servants came and told him about the well they had dug. They said, "We've found water!" 33 He called it Shibah, and to this day the name of the town has been Beersheba.
34 When Esau was forty years old, he married Judith daughter of Beeri the Hittite, and also Basemath daughter of Elon the Hittite. 35 They were a source of grief to Isaac and Rebekah.
Also read Genesis 20:1-18 and 21:22-34