I'm so sorry you're going through this, I have been there before.
Google "the drama triangle," understanding the concept helped me break the cycle of him behaving unacceptably, me closing him out, then somehow apologizing as if I had done something wrong.