Scotland Yard said the man, thought to be in his 50s, was spotted carrying two knives outside the central gate of the London tourist landmark. He did not threaten other people at the scene, but when challenged by police he acted aggressively.
Officers used the stun gun on him and took him to a London police station, Scotland Yard said. No one was injured.
A video posted onto YouTube by a witness showed mounted police clearing tourists from the area as the unidentified man put a kitchen knife to his neck and shouted. The man took several swipes with one of his knives at an approaching policeman, who fired the stun gun. The man then fell to the ground and was surrounded by policemen in front of hundreds of onlookers.
Other witnesses said the man had broken through a security cordon and was attempting to walk toward the palace guards when he was stopped by police.
About 15 officers surrounded the man once he'd been subdued, said witness Kevin Burrows, 33. "Everybody was standing back when it happened, and people were actually quite calm. I think everyone was surprised," said Burrows.
The confrontation took place just before noon—a busy time when visitors from around the world flock to the front of the palace to watch the Changing of the Guard ceremony, which takes place every other morning during the winter.
Two knives and a pair of sneakers were left inside a cordoned off area outside the palace gates.
Queen Elizabeth II and her husband, Prince Philip, were not at the palace at the time, and its staff declined to comment about the confrontation.