The German exchange student had been targeted by the men while he was riding the late-night train home, The Sydney Morning Herald reported.
They demanded he give them his wallet but when he refused and got off the train, they followed.
They pounced as he made his way through a dark alley in Sydney's west.
They grabbed his phone and iPod and kicked him while he lay on the ground.
However, the men were spotted by a member of a nearby dojo.
Nathan Smith told his sensei and the rest of the students at Ninja Senshi Ryu and they rushed out to confront the thugs - all dressed in traditional black ninja garb.
On seeing the ninjas, the men fled, only to be later arrested by police.
Oh man, I'd like to think there's a special place in prison for robbers thwarted by ninjas. And that place is in the arms of the biggest pirate in there. Because you're his bitch.
Ninjas rescue student from muggers [heraldsun]
Thanks to Zach, Ben, a-kill, Ambrose, Patrick, Nick, Chrit, Thandorbeast, Zikomo, Marc Eagle, Elise and Roy, who can scare off robbers without ninja costumes because they're badasses. Kidding, they all carry firearms.