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 knife to his neck and shouted. The man fell to the ground in front of onlookers as one officer used the stun gun on him.
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.