The strict ban on German military operations within the country was adopted following World War II, in reaction to the Nazi regime having used the army and paramilitary forces for its domestic agenda.
On Friday, the Federal Constitutional Court said the Bundeswehr armed forces could deploy under strict conditions in case of an assault in Germany with the potential for scores of casualties.
The deployment of troops in Germany was only acceptable in "states of emergency of catastrophic proportions," the judges ruled, but never "in reaction to the threat posed by demonstrating crowds".
The use of combat weapons was only acceptable "as a last resort" and must be approved by the federal government, not simply delegated to the defence minister.
Shooting down a hijacked passenger plane with civilians on board remained illegal after the ruling - but fighter jets could attempt to force such an aircraft to land with warning shots.
The ruling marked a reversal of a decision by the same court in 2006 and was a response to complaints from two of Germany's 16 federal states.
The German government had attempted to allow more flexibility in its military response to a possible terror attack in the wake of the September 11, 2001 suicide hijackings in the United States.
But it ran into resistance from the court, which cited strict restrictions on the deployment of the military in Germany set down in the post-war constitution.
Fears also ran deep that the armed forces could be used as an instrument of political power.
The decision effectively broadens Article 35 of the constitution which only permits a domestic military deployment in case of a natural disaster or a particularly serious accident.
Defence Minister Thomas de Maiziere and Interior Minister Hans-Peter Friedrich welcomed the decision in a joint statement.
"Ensuring the security of our citizens, particularly in extreme cases, is one of the most important duties of our state," they said.
The ruling "fills a legal void", added defence affairs expert Ernst-Reinhard Beck of the ruling conservative Christian Union parties' parliamentary group.
However Justice Minister Sabine Leutheusser-Schnarrenberg stressed the importance of the "separation between internal and external security" and noted that "not everything that is constitutionally possible is politically right".
Story continues below…
The opposition Social Democrats welcomed the "last resort" restrictions imposed by the court, home affairs expert Michael Hartmann said.
But the far-left party Linke warned that the decision "opens the door to a further militarisation of home affairs and hollows out democratic rights".
In a dissenting opinion, Judge Reinhard Gaier said the court had gone beyond its powers, and that the government should seek an amendment to the constitution if it aimed to deploy the military on German soil.