The naked middle-aged man jumped into the moat, then threw rocks and splashed water at two policemen who chased him in a rowing boat, a Tokyo Metropolitan Police official said.
The police official did not know the man's name or nationality. Public broadcaster NHK and Kyodo News agency said the man is believed to be a 40-year-old Briton living in Spain who visited the moat with several Spanish friends.
TV footage showed the man swimming around the moat as the police chased him with a long stick, attracting a crowd of onlookers. He was in the water for about an hour.
He eventually got out of the water and climbed a stone wall only to fall into the hands of police waiting for him. The police official said the man was detained for questioning, but could not confirm if he was arrested or charged.
A palace official said Emperor Akihito was in the palace, but it was unlikely he saw the nude swimmer.