Matthew Perry once beat up Canada's Prime Minister, Justin Trudeau ... and he thinks it pushed the guy into politics.

Matt was on "Jimmy Kimmel Live!" Wednesday, and he told the story of how he and his buddy beat up a 3rd grade Justin for "excelling in a sport."

It's pretty funny -- Justin's dad was the PM at the time and didn't have security around his boy. Jimmy rightly points out nobody could get away with that around Barron Trump.

Even crazier ... Matt doesn't think Justin would be where he is today without that pounding.