A man swinging a samurai sword fought an imaginary duel Friday on the glass spiral staircase of the bustling Apple Store on Fifth Avenue as frightened tourists and computer geeks looked on.

Video posted to Instagram shows the swordsman walking up the staircase, and then sitting on it while performing pretend lunges and parries for his startled audience at around 3:55 p.m.

He was quickly tackled by Apple security and turned over to police, who took him to Bellevue Hospital for a psychiatric examination.

Nancy Birnbaum, a lawyer who lives in the area, was browsing at the store when she saw the man on the staircase suddenly unsheathe his weapon.

“Usually the staircase is mobbed with people, but this time it wasn’t. There was a guy in the mid part of the staircase kneeling,” Birnbaum told The Post.

“His face looked a little contorted and twisted,” she added. “I thought he was doing some sort of performance art, but then he pulls out this sword with a huge 2-foot-long blade and it was dead obvious that it was a real sword.

“I’ve never been so terrified in my entire life.”

Birnbaum said that she feared the worst.

“I don’t know if he is from ISIS or wherever the heck he is from but I thought this is the beginning of some sort of horrible headline tomorrow,’’ she said.

“Thank God it wasn’t,” she added.

Customer Luis Apolo, 18, says he at first thought the man was holding a simple stick.

“I was sitting right under the stairs when he started talking loudly to one of the employees,” Apolo told Gothamist.

According to Apolo, the man “got mad” before he whipped the sword out, “swinging” it around on the staircase.

A store worker who asked not to be identified said, “[He] put the sword at the back of his neck but he never cut himself.

“Security came and tackled him and he went down,” the worker added. “They held him down until more police came and took him to the hospital.”

The man, whose name was not immediately released, faces charges of criminal possession of a weapon, according to police.