After the Middle Kingdom Egypt lost interest in maintaining its borders, the king withdrew troops and allowed the Nubians to occupy its southern forts.
Meanwhile, semitic immigrants called the “Hyksos” entered Egypt and settled in the north. Hyksos rulers competed with the native Egyptians and even allied with the Kushites/Nubians.
Seqenenre Tao and Kamose, the two final pharaohs of the Second Intermediate Period, fought back against the Hyksos. After Kamose died, his younger brother Ahmose (after waiting a few years to come of age) ousted the last of the Hyksos and became the first pharaoh of the New Kingdom.