The best way I have found is to make them plot devices in the games rather than characters.
When these types of character are defeated in the stories, they are usually not overcome by force (in fact, the inability of 99.9% of the universe to overcome them by force is pretty much the definition of a "cosmic level" character), but rather by trickery (usually involving a vulnerable element in the critical path of their plan), stalemate (we can't stop you from taking, but we can destroy what you want), or moral conflict (WRT the being's own philosophical framework). Winner-take-all slugfests against this type of character are usually not satisfying. Usually these stories have the heroes struggling to survive against the cosmic power's onslaught in order to implement a non-brute force solution.
For cosmically powerful heroes, while they have the capability to do practically anything they can conceive of, their actions are usually limited by external controlling factors like morality (won't kill and won't interfere being the two most frequent), consequence (when I do this good thing, something else bad will happen), or focus (a djinn can't create something they haven't thought of or respond to something they didn't notice). Whatever the reason, cosmically powerful heroes only participate in a limited way, based on the circumstances.
Working from these premises, this type of character should be somehow isolated from the lower-level conflict in your game. They become part of the scenario. They don't (often or much) engage in direct combat and the way to counter them is part of the scenario objective rather than direct combat.
Often, unlikely bedfellows will have to collaborate, for a time, in order to achieve the objective. This creates two lines of dramatic tension: (1) how can we overcome this powerful force? and (2) when will we turn on each other?
There is always the "interest motif" where a cosmically powerful entity only involves itself in the few ways it cares about what is going on. It will ignore lower-level characters unless they are directly in their way.
A good subtype of the interest motif is the scorpion fight story where an uber-powerful entity collects others and forces them to fight, usually from curiosity or boredom.
For the knockdown between such characters, a great approach is to separate the battle and have the powerful characters affect the environment of the others. F'r'ex, I had a scenario where Supes and Doomsday had a duel in the middle of an JL/IL battle. As the S&D characters fought, they careened around the board, destroyed terrain, and got in the way of lines of approach/lines of fire. The lower level characters had to fight around the other two. Eventually, when one was victorious, it was so beat up that subdual by the lower level characters was possible.
Another classic is the rescue mission, where one side doesn't have the power to overcome the antagonist, but they can sneak away with the hostage. There is also the approach where the antagonist becomes bored, impressed enough, or is spending too many resources so they give the hostage up. The X-Men rescue of Arcade from Doom or Nightcrawler from Margali are great examples of this motif.
A hero or villain of this magnitude can create good scenario mechanisms. Like the clock – must replace the gate wards before Dormammu becomes incarnate in this reality; must keep the defenders from interfering with Superman while he works to destroy the world-annihilator bomb, as only he can do.