Attacks from the outside are easy enough to prevent. Just make your empire massive and powerful enough that there's no other entity powerful enough to even think of attacking it without inviting certain doom to itself.
Welcome to the Empire of Asnitria. The word "you" in this answer refers to the group of people in charge of the empire.
It doesn't necessarily imply a single person. It may in fact be a council, family, clan, ancient tribe, cult, etc., or some combination of some of those.
The biggest concern is people turning against you. Therefore, it's very important that you have proper control of the media in the empire. The fourth estate is extremely powerful, and you can't have the possibility that anyone with money could grab it and use it to counteract you. All major media outlets need to be controlled. However, this should not be apparent! All the big media outlets need to appear to be independently owned, and to disagree with each other, support different political ideologies, etc. These "disagreements" will be over relatively trivial matters. (Like whether tax should be at 20% or 24%.) Or over social matters that you don't really care about, but the people do. However, they will be blown out of all proportions in order to distract the public so that they don't think about opposing your agenda when it comes to the issues you do care about. (Like the empire being undivided. And nobody discussing the fact that the media is controlled.) If the media disagrees over vital issues, it will only be over details. The main line that the you want pushed will be agreed on by all the major media outlets. Again, the details will be blown out of all proportions, so that the public start arguing over them and get distracted from the problems you don't want them to focus on.
To make sure you can control these media organisations, only use thoroughly corrupt people to run them. These people should all have plenty of black money, sex scandals, financial misconduct, etc. under their belts, but all unpublished and not known by the public. You, however, have a complete file of evidence on each of them that so that you can easily take out anyone who even tries to oppose you.
You could use brute force to control people, but people would be discontent, and it would be easier to undermine you. On the other hand, the problem with real democracy is that it's too chaotic, and the empire will split up way too early. How to solve these two problems?
The most important thing is to control people's minds. As long as most of them believe they are living in a democracy, it's enough. Find yourself a handful of people as potential "leaders". You need to take the same strategy with them as with the media people, having a file of incriminating evidence against them should anyone get out of line. They will all follow your bidding. (If they don't want to be disgraced or killed, that is.) Of course, there's a carrot, too. People in your camp are compensated well and can live luxurious lives. And if they continue doing more dirty stuff, it's all the better for you. It gives you more evidence to sweep under the carpet, or rather, into your blackmail archive.
Actually, this register of files will be quite large. It needs to be taken care of very carefully, by only the most trusted men. Also, there needs to be backup copies. The moment some politician or powerful person is unloyal to you, you will leak a video of them sleeping with an underage prostitute or something. Part of the reason you have such evidence on everyone is because you specifically select such people. If there's someone you want to enlist, you can also arrange for them to end up in such a situation or, indeed, manufacture the evidence.
Set up elections, and have various media outlets pretend to be partial to various candidates. Your candidates will fight bitterly against each other during their campaigns. However, their areas of disagreement will again be trivial. On the matters you care about, all the candidates will take roughly the same line. If any truly independent candidates try to run, you merely have the media ignore them. Or, if necessary, smear them, or worse, arrange for an "accident".
Anyone who tries to talk about this rigged, phoney system of yours will be ridiculed (if addressed at all) by the media and labeled a nutcase.
Now, all discontent will be directed into this system. The people are pissed off? Direct it towards the phoney leader, not you. In fact, no one in the public even knows who you are. They think your puppets are the real leaders. Therefore, whenever things go really bad, the puppets will go to the gallows, not you. There will be a new candidate (also under your control) talking about red roses and change, condemning the past leadership very strongly. The people will love him or her.
Really, really, really dumb down the masses
To prevent the masses from suspecting what's going on, you need to really dumb them down. The intellectual level of TV, movies, music, etc., must get lower every year. Elementary education should serve as a form of brainwashing. Higher education should be highly specialized so that people can be skilled at their jobs without seeing bigger pictures. Higher education in the liberal arts should also serve as a hierarchical system that conditions academics to promote views you prefer. Use your media monopoly to frame critical thinkers as paranoid nutjobs.
Regardless, a portion of the population will realize what sort of rigged system they are living in. They won't be too big of a threat to you, because the masses will see them as nutty outsiders and conspiracy theorists. The media will routinely refer to them as such. You can also use various disinformation tactics and infiltrate them to weaken them. You also need to start a bunch of conspiracy theory media. These outlets will present roughly 30% truth, and 70% rubbish. (Flat earth, ancient aliens, etc.) The presenter will be some sort of quite emotional guy who is shouting at the top of his lungs with streams of sweat dribbling down his forehead. This type of crazy conspiracist media will be well funded. Also, by the help of the normal media, it will soon be the sort of crazy thing the masses will associate with that sort of thinking. Thus, you have discredited such thinkers and dealt with that contingency very well.
The type of propaganda that you do want people to believe in, on the other hand, will be seen as balanced, reasonable, factual news.
A terrible, external enemy
Let's put aside hegemony for a while. There may actually be another another, large empire in the same world. The two empires are of roughly the same size, power and type. For simplicity, I'm calling the other empire Blevtaya. Blevtaya is not a mock democracy like yours, it's an openly brutal, authoritarian regime.
The governments of both these empires realize that a war between them would be utterly disastrous for both parties, and therefore they would do a lot to avoid such a war. However, they both have a problem. They need to prevent separatist factions within them from being created.
The leaders of these two governments secretly get together and discuss a plan to deal with this. They both have the same problem. They can both solve it in the same plan. They will both agree to a phoney conflict escalating between them. It's easy to stage a conflict when both sides are in on it. Obviously, it's never going to come to a full war, as neither side wants that. It's just going to be the constant threat of that, to be used as a propaganda tool. Only your closest men will know for sure that it's phoney. The rest of the government apparatus will not be told that. So, step up military exercises, make extreme, historically hostile public announcements, stockpile dangerous weapons, ramp up military expenditures, etc. Of course, the elite politicians all own lots of stocks in top military contractors, so they don't exactly mind this expenditure of taxpayer money.
If you need to further convince the public that the conflict is real, there can be actual violent actions. For example, you can launch theatre wars on regions outside the two empires. Both empires have an interest in a region known as Ciratnaya. There's a puppet regime there that's loyal to Asnitria. (However, the public doesn't know that that regime is a puppet regime.) Blevtaya starts funding, training and giving weapons to some rebels there in an attempt to overthrow that regime and install one suitable to their interests. Thus, a horrible "civil" war ensues in Ciratnaya. The media needs to keep repeating that the war may go global at any minute, and keep scaring the public with the prospect of a devastating war between the two empires.
Here are some key elements from the media in Asnitria:
- The government of Blevtaya is absolutely horrible. They use WMDs on civilians, use child soldiers, etc.
- They want world dominion. We need to stop their efforts in Ciratnaya.
- They'll stop at nothing otherwise, and we will be their last victim.
- There will also be some media that opposes the theatre war, just to keep it seemingly balanced. But even they will agree on some of the horrible, underlying facts, fueling the public fear.
- Antagonistic statements from leaders of both empires, ramping up public paranoia.
There needs to be a constant, public fear of global war.
This will let you:
- Talk about patriotism and rally people behind you and the empire.
- Accuse people who oppose you of being in line with the enemy.
- Give greater liberties to the secret police, etc. under the guise of national security. It will then be easier for you to spy on the public, arrest people without evidence, etc.
You can have this tense situation go on for a very long time. Whenever the public's fear seems to calm down, arrange some new war or serious conflict between the two empires, and ramp up the warmongering and propaganda. They'll be too scared and patriotic to pose a problem for you.
One of the problems with having Blevtaya be the enemy is that it can't escalate too much. You don't want a full war against Blevtaya.
Therefore, another option is terrorists. Of course, you don't want real terrorists, because those may actually be dangerous to you. You need some mock terrorists that attack public targets, etc. When you really need to get the public in the proper mindset, stage a "terrorist attack" somewhere.
The agents perpetrating this will be absolutely vile creatures. You'll find paedophiles, rapists, serial killers, etc, and give them highly specialized training. You need the type of calculating psychopaths who are horribly depraved but yet stable enough to think "clearly", receive training and follow orders. Unfortunately for humanity, such people do exist. The unwritten law of this shadowy organization is that anyone who steps out of line will be either exposed as a paedophile rapist, or tortured and killed. By the way, all your top power networks and secret police work the same way.
You'll blame the terrorism on some elusive terrorist group, or even on the sympathizers of some separatist movement you want to discredit. The "advantage" of these attacks is that they can be absolutely horrible, and kill hundreds or even thousands of innocent civilians in normal cities. (I'm sure you have realized by now that the government of Asnitria is absolutely disgusting. If this isn't what you were looking for, then I'm sorry. But I don't see any other way you'll have even a chance at 10.000 years.)
After staging such an absolutely horrible "terrorist attack", there will be no nation state to retaliate against. So you can have the horror without the ensuing war. Of course, you can also blame the attack on some small nation that you wanted to take out anyway. The terrorist attack gives you largely the same benefits that the war with Blevtaya did. The public will be afraid, and thus very easy to control. The government can increase its power, due to the an alleged need for increased security. You can also discredit people by accusing them of being in line with the terrorists, etc.
Divide and conquer
In whatever way you can, keep the people fighting among themselves. Preferably not by geographic regions. You want your empire geographically united. No, keep them fighting over race, ethnicity, language, religion, trivial politics, ideology, sports, sexual orientation, gender, caste, belief, social class, whatever. It is better if each province has a lot of diversity when it comes to those traits. You don't want large homogenous provinces with just one type of people in them. Such provinces are more likely to unite in a strong sense of nationalism, separatism, etc. You don't want that. It's better if you mix lots of diverse groups of people in each province. Divide and conquer is very easy in such mixed provinces. Also, you want each province economically dependant on other provinces through finances, trade, multi-provincial corporations, etc. This will make the very idea of separatism hard if not impossible. And again, induce conflicts not between provinces, but within provinces, based on the social aspects referred to above. As long as you give them something to fight over, it will keep them from uniting against you. You can also use the media to fuel such conflicts and divert attention away from the actually significant activities of the government.