A gunman opened fire in Turkey's highest administrative court Wednesday, wounding five judges in an attack he called retaliation for a recent decision against a teacher who wore an Islamic-style head scarf, officials said.

At least one of the judges was in critical condition, they said.

The attacker, who was detained and being interrogated by anti-terrorism police, chanted "Allahu akbar!" or "God is Great," as he fired, private NTV television reported, citing witnesses.

Tansel Colasan, deputy head of the administrative court, the Council of State, told reporters that the attacker also shouted "I am the soldier of God," and said he was carrying out the attack to punish the court decision on head scarves.

The judges, all from the same court chamber, had been severely criticized for a February decision barring the promotion of an elementary school teacher who wore a head scarf outside of work.

"This attack will go into the history of the republic as a dark stain," President Ahmet Necdet Sezer said in a statement.

"These attacks will never reach their goal," Sezer said, adding that the justice system would not be intimidated and would fulfill its duty with "loyalty to the secular and democratic republic."

The country's staunchly secular military also denounced the assault.

"I condemn this vile attack with hate," said Gen. Hilmi Ozkok, chief of the General Staff, in a message to the administrative court, according to NTV.

The attacker told police that he shot the judges to protest the court decision, private a Turkish cable television channel reported. The attacker was carrying a lawyer's identity papers, and police are investigating whether they belonged to him.

Under Turkish law, women are not allowed to enter schools or other public buildings wearing head scarves, and the wives of ministers are excluded from government functions and formal state dinners if they wear them.

Some 99 percent of Turks are Muslims. The country's secular establishment, however, which includes the courts and the military, has sought for decades to restrict Islamic influence, which some political leaders view as an obstacle to Western-style modernization.

Prime Minister Recep Tayyip Erdogan's wife, Emine, wears a head scarf, and his governing Justice and Development Party has made no secret of its desire to lift a ban on wearing head scarves in government buildings and universities.

Erdogan's government had condemned the court's recent decision, and pictures of the judges were printed in Islamic-oriented newspapers.

Deniz Baykal, chairman of the main opposition Republican People's Party, held Erdogan's government responsible for the attack.

"I hope those who still can't see where Turkey is being dragged, who refuse to see it, will take this as a warning," Baykal said. "Unfortunately, blood has spilled into politics in Turkey. Turkey is being dragged into a very dangerous situation. Everybody should come to their senses."

Erdogan also condemned the attack and said the culprit would be severely punished.

The head of the court chamber, Mustafa Birden, was wounded in the liver and the spleen and was underwent successful surgery, Dr. Ugur Erdener of Hacettepe University Hospital said.

Birden had received death threats recently, and the administrative court had complained that its members could become targets.

Judge Mustafa Yucel Ozbilgin was in critical condition and undergoing surgery for a bullet wound to the head, which caused severe brain damage, Erdener said. A sixth judge escaped the attack unharmed, having thrown himself onto the floor, reports said.

The governor's office in Ankara confirmed that five judges were wounded in the attack.