The Federal Constitutional Court in Germany says the military will in future be able to use its weapons on German streets in extreme circumstances.
The ruling says the armed forces can be deployed only if Germany faces an assault of "catastrophic proportions".
The decision to deploy forces must be approved by the federal government.
Severe restrictions on military deployments were set down in the German constitution after World War II.
The BBC reports that the court has now changed that, saying troops could be used to tackle an assault that threatens scores of casualties.
The judges had in mind a terrorist incident involving armed attackers in public places.
German troops have been deployed abroad since the war, but it has been a gradual process.
German warplanes were used in the Balkans and troops are on the ground in Afghanistan. They are able to return fire if attacked.