Amid the wave of jihadist attacks in Europe, German lawmakers voted in favour of the law designed "to reinforce the effectiveness of criminal procedures".
German investigators will now be able to insert into users' cellphones and computers spy software (or a "Trojan horse") to access data in encrypted message services such as popular applications WhatsApp and Skype, including as part of criminal investigations.
Up to now, such surveillance tools were not authorised by the German Constitutional Court as part of the anti-terrorism fight.
The new law is seen as a significant change for a country that usually is very protective of private information, given the burden of Germany's past dictatorships, the Nazi regime in the 1930s-40s and the communist government in the east of the country after the war.
Interior Minister Thomas de Maiziere welcomed parliamentary approval of a law which he believes will correct a technological lag on the part of the state in dealing with criminals who, along with the population at large, use these applications all the time.
The opposition far-left and Greens parties voted against the law, however, criticising it as an unlimited extension of a surveillance tool in the country.
The debate stretches far beyond just Germany.
France and Britain, also targets of recent attacks, want to establish a system of legal requirements regarding encrypted services to reinforce Europe's fight against terrorism.
WhatsApp, acquired by Facebook, and Skype use data encryption to guarantee user confidentiality.
They have refused to bend to laws which some countries have imposed on traditional telecommunication operators - mobile and fixed phone companies and internet providers - to provide data at government request.