Ted managed to win against AM by doing the one thing the AI would have never expected: Killing the other survivors in a way that AM cannot bring them back. While this goes badly for Ted, it is an undeniable victory, and the severity of Ted's punishment shows not only just how badly he has hurt the AI, but also how much the AI fears what would happen if Ted was ever given any kind of ability to move or act in a meaningful way again.
Moreover, in his current state, all Ted can do is suffer from the pain of his punishment, leaving the AI to only watch his victim's fate in boredom, as it cannot construct mind games, physical or psychological tortures, or any of its other prior methods of torment that it once had used for fear that Ted will take any opportunity allowed to him to end himself. AM has been denied the one pleasure it had in its existence, the one distraction with which it could while away its existence, and can only count the seconds as they pass... forever.
Minor one, but instead of being scared when AM calls for him in the game's intro, Nimdok simply scowls back.
In Ellen's scenario, she is confronted by the image of the yellow-clothed rapist who assaulted her in the elevator. However, you can choose to fight back. Sure, the animation may be Narmy to some extent, but that's offset by the fact that she's beating the shit out of the man who raped her.
Just the way you do it is awesome. You do it by shutting down the three parts of his mind by throwing logic bombs at them.
The Id (the part most obsessed with torturing the survivors) is defeated with the Totem of Compassion, showing you empathize with him and removing his will to live (seeing as that part of AM existed trough his hatred).
The Ego (the most logical part of AM) is defeated through the Totem of Forgiveness, basically forgiving AM for what he did; causing him to short out from trying to fathom why they would ever forgive him for all he's done to them. (Seeing how the Ego's main job is acting based on a database of all humanity's recorded violent crimes throughout history, this part of AM's being is probably entirely bound up in the concepts of rage, escalation, retaliation, and revenge. It makes sense that being confronted with the idea that is possible let go of one's anger and answer a transgression with forgiveness and de-escalation instead of more violence are so completely alien ideas to him that he simply cannot fathom them.)
Finally, the Superego (the part most obsessed with self preservation) is defeated by the Totem of Clarity, driving him to suicide by the revelation that no matter what he does, he will eventually break down and rust into nothingness.
A meta one: Harlan Ellison's voice acting for AM. He really nailed AM's personality in an epic, hammy portrayal, and is clearly enjoying doing it too.