The obvious solution is to promote them. If you don't reward loyalty don't expect loyalty.
Not everyone is great at the level above and even if they are, sometimes it is not always a good fit for them. I've had more a good few engineers ask to go backwards when they've been promoted - each for their own reasons but nearly always around the theme of being in a position of leadership / seniority.
But if you reward loyalty over skill then don’t expect skill to stick around.
Some people have 5 years of experience and some people have 1 year of experience 5 times.
Indeed, with a big BUT: you don't want to overvalue loyalty in respect of competence. You don't want to have a boss that is not good but "is here since forever".
Instead, reward them economically. Everytime the company takes a leap forward, make clear to them that they were important for the process, and share some profit.
And make clear that being important in a moment doesn't automatically mean they will be important in the future: they will have to compete on results, like everyone else.