The German military will in future be able to use its weapons on German streets in an extreme situation, the Federal Constitutional Court says.
The ruling says the armed forces can be deployed only if Germany faces an assault of "catastrophic proportions", but not to control demonstrations.
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 Nazi-era abuses.
The court says the military still cannot shoot down a hijacked passenger plane - fighter jets would have to intercept the plane and fire warning shots to force it to land.
After World War II the new constitution ruled that soldiers could not be deployed with guns at the ready on German soil, the BBC's Stephen Evans reports from Berlin.
The court has now changed that, saying troops could be used to tackle an assault that threatens scores of casualties.