A scene straight out of “MacGyver” unfolded during Wednesday’s shooting at the Canadian Parliament building, when Conservative members of Parliament prepared to do battle by taking down flagpoles and sharpening them into spears — all while Prime Minister Stephen Harper cowered in fear inside a nearby cabinet.

The innovative lawmakers inside had no idea that Harper had spent 15 minutes in his tiny hiding spot while they rapidly barricaded the entrance doors to a meeting room in an attempt to stop crazed gunman Michael Zehaf-Bibeau.

The Muslim convert shot and killed a Canadian soldier Wednesday before storming the Conservative caucus building. His rampage continued inside, where he also wounded a security guard, who is expected to make a full recovery.

Brandishing their newly created weapons, the brave parliamentarians lined up alongside the doors as they waited for Zehaf-Bibeau to enter.

“These guys were up there holding these spears ready to impale anyone who came in,” an anonymous member of Parliament told Canada’s Globe and Mail. “It was that or get mowed down.”

Shortly after gunshots began to ring out inside the building, Harper was rushed into the cabinet by officials in the Center Block room, where 150 Tories began transforming their flagpoles into bayonets.

“There were 15 flags up at caucus and all but two were taken down,” the lawmaker added.

The legislators knew someone was in the tiny cabinet, described no bigger than a “cubbyhole,” but weren’t aware of the significance of their protective efforts until Harper’s personal security detail removed him from the site, according to the Globe and Mail.

“Someone knew there was a closet there, so they stuck him in there,” the lawmaker said. “So for a lot of people, it was as though he was gone.”

The converted flagpoles were such a hit that some members of Parliament even decided to keep them as souvenirs.

“Everyone was taking their spears home,” the anonymous lawmaker told the Globe and Mail. “I’m going to frame mine.”