The gunmen, in their early 20s, were detained on the roof terrace of the Burger King restaurant in central Istanbul after one of them fired his pistol into the air, said a Reuters reporter at Taksim square, which had been surrounded by police.
Celalettin Cerrah, Istanbul's chief of police, said the two men, who had gone without leave of absence from the army in Egirdir, had taken several people hostage but none had been harmed.
Cerrah said: "They said they were carrying out this act to protest at the incidents in the southeast in recent days."
Clashes between the security forces and the outlawed Kurdistan Workers Party (PKK) have escalated in recent weeks. A rebel group linked to the PKK has also claimed responsibility for a series of bombings in recent days.
A man, who gave his name only as Cengiz, said as he carved a kebab at one of the food restaurants on Taksim square: "It seems they were very upset by what has happened in the southeast. They shouted that nothing was being done to protect the martyred soldiers."
Dozens of police flanked the mini-van which took away the two men, wearing red and white T-shirts with the word "Turkey" on them, with locals booing them as they left.
Police said they believed the men were brandishing air pistols, adding one restaurant cashier and a customer had been taken hostage before the men proceeded to the roof.
Police climbed on to the roof to overpower them. Hundreds of police were at the scene.
Upsurge in violence
The incident comes amid an upsurge in violence in the country.
Earlier on Saturday, a mine killed two members of Turkey's security forces after soldiers killed six guerrillas fighting for Kurdish autonomy, officials said.
More than 30,000 people, mainly Kurds, have died in the conflict since 1984.
On Friday, a bomber blew herself up near a mosque in the Black Sea city of Ordu, while three people were injured in a bomb attack in the southeastern city of Diyarbakir, security officials said.