Your story has to make sense, the plot has to make sense.
It has to seem like the characters are making realistic decisions for their situation, with their goals. What they say and do cannot come out of nowhere, or be left unexplained. How they do it cannot come out of nowhere, or be left unexplained.
When your readers say "WTF, where did that come from?" or "Ohhhhh, reaallllly," or "What a fortunate coincidence!" then you have likely built a Deus Ex Machina, something that is going to take them out of the reverie of reading about your world back into the real world, where they realize a bad author is behind this story, and the characters and setting are just puppets.
An antagonist cannot disappear for no good reason.
The reason has to appear realistic to the reader, make sense to the reader, and cannot look like just "good luck" for the main character(s). You cannot just make up some coincidence that kills the antagonist, or turns him back to the light side, or or makes him leave so he's out of the way. You have robbed the MC of their responsibility to deal with the antagonists.
A story is about the MC confronting adversity, a problem, something wrong with the world, and either prevailing or failing or some combination of both, at the end, prevailing with their wits and skills despite their mistakes and weaknesses, or failing because of their weaknesses despite their wits and skills.
If you just get rid of an antagonist by surprise, that is not the MC either prevailing or failing, it is just nothing. In real life, a girl being bullied in school might find relief when the bully's family relocates to another state. But that isn't a good story, the bullied girl did not solve her problem, she suffered bullying and then it stopped. She did not show any courage or cleverness or fighting back, she did not learn anything, and did not accomplish anything.
Your antagonist can leave, or die, or go to jail, but if your protagonist has nothing to do with that, then you don't have a good story. Even if it is not the main antagonist. You cannot "save" your protagonist by just making the antagonist give up and go elsewhere.