Russian police stand guard during a protest against the jailing of opposition leader Alexei Navalny in Siberian city of Omsk, Russia, Saturday, Jan. 23, 2021. AP
Public calls to act against Russia's security will be punished by up to seven years in prison.
Establishing and maintaining "confidential" cooperation with a foreigner or international organisation and helping them act against the interests of Russia will be punishable by up to eight years in prison.
The development brings to mind the Soviet era when contacts between Russians and foreigners were strictly monitored.
Lawmakers also toughened legislation on state treason and espionage.
The measures were passed on the 133rd day of Russia's military intervention in Ukraine.
Russian society is reeling from a historic crackdown on dissent which has intensified since President Vladimir Putin sent troops to Ukraine on February 24.
Rights activists fear the new legislation will be used to snuff out any last vestiges of dissent.
"The changes are an adequate and timely response to the challenges that our country is currently facing," senior lawmaker Vasily Piskarev said in a statement released by the lower house of parliament.
Collecting, storing and transferring to the enemy information that can be used against the Russian army will be considered a form of espionage and is to be punishable by between 10 and 20 years in jail.
Putin's decision to send troops to Ukraine has led to a further clampdown on freedom of speech and media in the country and sparked an exodus of foreign and independent Russian journalists.
Criticism of Russia's military intervention in Ukraine has essentially been banned in the country, and the words "war" and "invasion" outlawed.
In March, Russia passed into law prison sentences of up to 15 years for spreading false information aimed at discrediting its military forces.