Have them be a spellcaster with access to high level spells
The easiest way to achieve effective immortality is to use spells. A wizard has access to several of them once they get higher level spell slots.
- Sequester will allow the BBEG to put themselves into a state of suspended animation during which they will not age. This will allow them to span any amount of time without aging (though it will mean that they are out of action for that time).
- Clone will provide the BBEG with fresh young bodies to use once their older body dies. With enough of these, they can last an infinite amount of time. See this Q&A for more discussion on this.
- Wish obviously wish can do anything, including granting immortality. A wish for immortality is unlikely to be granted in a straightforward manner though and would be a good opportunity for the DM to implement some sort of curse or other downside on the BBEG as a result of their wish.
- Imprisonment is an option but it would require someone else to cast it on BBEG and for them to let them out again.
- Reincarnate, revivify, resurrection, true resurrection can obviously also bring BBEG back from death assuming there is another caster capable and willing to cast it on them.
Instead of having the BBEG be a spellcaster, you can always have them have the assistance of someone or something capable of casting the spells. For example, Djinni can cast wish as well as some magic items. This can be a good solution in the case that making the BBEG high enough level to gain access to the spell themselves would be too much for the party to fight against.
Be a high level Druid or Paladin
At 18th level, druids get the Timeless Body feature:
[T]he primal magic that you wield causes you to age more slowly. For every 10 years that pass, your body ages only 1 year.
Combine this with a long-lived race like the elf or warforged and you easily have thousands of years of life.
An Oath of Ancients paladin at level 15 gets:
Additionally, you suffer none of the drawbacks of old age, and you
can’t be aged magically.
Which seems likely to be able to prevent death from old age as well if your DM interprets death from old age as a drawback. (thanks @Walt)
Grant an Epic Boon
As Carcer points out in their answer, a DM can use the Epic Boon of Immortality to grant BBEG Immortality. This assumes that they have 20 PC class levels and may not be justification enough for BBEG being immortal plot-wise, but it is an available mechanic.
Magic items
The Ring of Winter listed in Tomb of Annihilation will prevent aging.
You, as DM can also feel free to invent any kind of item or artifact that can prolong life as well. Just be sure you are fine with having it fall into the PC's hands or have some sort of plan to have them need to destroy it.
In fact...
Make something up
If none of the RAW options above satisfy you, make something up. You are the DM and you have the power to change your world to contain whatever effects you want. Perhaps, the villain found or made a powerful artifact. Or maybe they found a sacred site or ritual that allows them to be long-lived. The options are really endless and really, there shouldn't be much of a concern here because the long-lived villain is a common trope and is not likely to be a problem for players to accept even without explanation.
Or even better, you can mix and match from all these options to create the long-lived villain of your dreams.