At the end of the Old Kingdom central authority dwindled and eventually collapsed, and Egypt went through a period of disunity known as the First Intermediate Period.
At first the various hereditary regional governors paid lip-service to the idea that there was still a king in charge of the whole country, but over this 125 or so year period this fiction was quietly dropped. A lot of our information about the period comes from inscriptions in the tombs of governors and needs to be taken with a pinch of salt. They tend to represent the state of the country as being utter chaos, and they alone were capable of bringing order to their region while everyone else starved & died. Modern historians think it was likely a lot less dramatic than that.
Once the fiction of a line of kings descending from Pepi II had vanished new powers rose to fill this vacuum. The 9th & 10th Dynasties ruled from Herakleopolis in Lower Egypt, consolidating their power over that region. A couple of different regions of Upper Egypt jockeyed for power, but the Theban rulers won out and under Montuhotep II they re-united the whole of Egypt and inaugurated the Middle Kingdom.