Well, the bad guys losing is realistic, at least for actual "bad guys" rather than simple "antagonists". That I think is an important distinction: movies where an antagonist wins is much more common than where a villain wins: the one that popped into my head immediately was the first Rocky Movie: the "antagonist" of the movie, Apollo Creed, wins the fight. But since Apollo Creed isn't really a villian, he's just another Boxer trying to win, there's no moral reason for him to lose, and the impressive thing with Rocky was how close he came to winning.
Villains is a different kind of antagonist, where there is something morally wrong with them. However, moral rules aren't just arbitrarily bad things: they're generally there to tell people not to do inherently violent things. The seven deadly sins are not just dangerous to the people the person committing them inflicts harm onto because of them, but to the person who commits them as well.
Thus, its actually I think somewhat realistic that a Villain loses, because doing villainous things is often self destructive to some degree, even if it takes time for their actions to catch up to it. To quote a very cheesy line, from Star Wars, "The more you tighten your grip, the more Star Systems that will slip through your fingers". The thing the Emperor was doing which made him evil, the desire control the galaxy personally, was one of the things that was weakening and undermining the Empire, and meant his Empire with a army to rival anything seen in the galaxy for a 1,000 years lasted less than a generation.
The more outright evil the villain is, the more self destructive they really need to be: like, take the Queen from Snow White: she was so vain and petty that she tried to kill someone who was implied to be her family, caused her henchmen to betray her, leading to her killing her henchmen in petty rage, and refusing to let such an immensely petty thing go resulted in her pointlessly putting herself in danger to try and kill a girl who is absolutely no threat to her, resulting her death to a bunch of very small men who before hand seemed to barely be aware of her existence. Her petty evilness led her to self destructive after self destructive act.
In a less fantastical example, someone who's just pure evil, say a serial killer, who's just doing bad for the sake of doing bad, realistically has a short shelf life: they're actions makes them no friends, makes a lot of enemies, and puts them in very personally dangerous situations. Now, serial killers do make great potential movie villains, we've seen a lot of them, and they will often make a couple of "victories" in the movie as they kill people or escape traps, but he rarely "wins", and that is the realistic outcome: it makes perfect sense that a serial killer is caught and "loses" in the end.
A serial killer winning in itself is a bit of a hollow concept: as a figure of near pure evil, there is nothing constructive to his goals: he's purely destructive force, and his only victory he's looking for is to go a bit longer without being caught so that he might have more time to cause more destruction.