Wait until the front wheels of the train pass the track junction, and then flip the switch.
This will derail the train entirely, since the front wheels are trying to go one way and back wheels another way.
Luckily this was a robot train, so no one was on board to be injured there.
And thus...