BERLIN — Every day as he settles into his desk, Erhard Grundl, a German lawmaker, looks outside his office window into the embassy he knows may be spying on him.

“I come into the office, and on a windy day, I see the Russian flag waving. It feels a bit like Psalm 23: ‘You prepare a table before me in the presence of my enemies,’” he said, chuckling. “I’m not religious, but I always think of that.”

In the shadow of Berlin’s glass-domed Reichstag, beyond the sandstone columns of Brandenburg Gate, German parliamentary buildings sit cheek by jowl with Russia’s sprawling, Stalinist-style diplomatic mission. For years, a silent espionage struggle played out here along the city’s iconic Under den Linden avenue.

Members of Parliament like Mr. Grundl were warned by intelligence offices to protect themselves — to turn computer screens away from the window, stop using wireless devices that were easier to tap, and close the window blinds for meetings.

It seems an almost comical situation for officials in one of Europe’s most powerful nations, where tensions over Russian espionage were something Germany’s government long seemed willing to ignore. That has become increasingly difficult since Russia’s invasion of Ukraine, as a Cold War-era style chill settles across the continent and recasts relations with Russia.

Late last month, Russia exposed what it described as a “mass expulsion” of its diplomats in Germany when it announced a tit-for-tat expulsion of more than 20 German diplomats from Moscow. It was a rare sign, security analysts say, of a subdued but growing counterintelligence effort that Berlin is now belatedly undertaking, after years of increasingly brazen Russian intelligence operations on German soil.

At least twice, Russian groups suspected of Kremlin links have hacked German politicians and Parliament — the last time just months before the 2021 elections that ended Angela Merkel’s 16 years at the helm and brought in Chancellor Olaf Scholz.

A few years earlier, a gunman accused of ties to Russian intelligence shot dead a Georgian dissident in broad daylight at the leafy Kleiner Tiergarten park, less than a mile away from Berlin’s government district.

In 2021, police arrested a security guard at the nearby British Embassy who had been spying for Russia.

And late last year, in perhaps in the most disturbing case of all, a German intelligence officer was unmasked as a mole passing surveillance of the war in Ukraine to Moscow.

Germany’s foreign ministry has been tight-lipped about the latest expulsions — even refusing to call them expulsions. But it acknowledged the diplomats’ departure was linked to “reducing the Russian intelligence presence in Germany.”

Expulsions were long a common German response to Russian operations — including the first parliamentary hack, in 2015, and the invasion of Ukraine, when 40 diplomats were sent back to Moscow. But security experts see the current move as part of a broader effort to bolster counterintelligence and chip away discreetly at what they long warned was an extremely high spy count at the embassy.

Still, analysts like Stefan Meister, of the German Council on Foreign Relations, said years of neglecting counterintelligence would take a long time to repair. When he worked with German spy agencies in 2000, he recalled, they did not have a single Russian speaker on staff. In contrast, he said, Russia’s president, Vladimir V. Putin, had long made Germany, Europe’s largest economy, a top target for espionage.

“We are not where we should be, or should have been,” he said. “The Russians are learning also. They have no limits, they have a lot of resources they put into this hybrid war, the information war. And we are always a few steps behind.”

“Finally, they expel these guys,” he added. “But why did it take so long?”

At the heart of the debate over Germany’s handling of Russian espionage is the Russian Embassy: a palatial complex of soaring stone towers engraved with Soviet hammers and sickles. It has long been a site of fascination, consternation and intrigue.

Before the full-scale invasion of Ukraine, even for years after Russia’s 2014 annexation of Crimea, the embassy was famous for lavish parties that attracted top German car industry executives, politicians, soccer stars and actors.

But it had a darker side: Two of its inhabitants have mysteriously fallen to their deaths from embassy windows. In 2021, a diplomat was found outside on the pavement by the German police, who believed he was an undercover agent of the FSB, the Russian secret service branch that Western officials linked to the Tiergarten murder.

It is an open secret that most diplomatic missions host spies among their ranks, and for years, a former senior aide to Ms. Merkel told The New York Times, she and her staffers who visited the embassy would trade guesses as to how many worked at the embassy there — sometimes suggesting up to 600.

In a recent documentary for ARD, the country’s state broadcaster, the estimate of embassy staff before the war was said to be more than 500. German officials generally assumed that at least a third of those were spies, the former Merkel aide said.

Germany’s domestic intelligence agency told ARD it found potential espionage equipment on the embassy roof — perhaps to spy on lawmakers across the street, like Mr. Grundl, or Frank Schwabe, from Mr. Scholz’s Social Democrats.

“We are not well enough prepared,” said Mr. Schwabe, who works in the building across from the embassy, and focuses on human rights. “I would actually like to see a targeted security strategy in Germany that really enables members of Parliament, to help them really arm themselves against these kinds of wiretapping attempts.”

For now, he offers visitors like Russian dissidents or civil society actors the option to move to another room — or to position themselves so their lips cannot be read.

Security experts say such tips are not nearly enough to help politicians who appear to be a top target — not just near the embassy, but anywhere, using vans with smaller devices that can tap into phones and hear conversations.

Mr. Meister said lawmakers with sensitive portfolios could be moved farther from the Russian Embassy. “Then again, what isn’t sensitive now? A domestic policy or other issues, like migration, could be used by the Russian side — there is almost nothing that isn’t sensitive at the moment.”

Indeed, Mr. Lang said issues like migration were a key topic used by Russia in identifying and recruiting frustrated, far-right sympathizing members of German security and defense forces — like the mole arrested last year, or the security guard stealing information from the British Embassy.

Complicating Germany’s efforts to effectively combat Russian intelligence is the country’s federalized system: Each German state has a different intelligence service.

Mr. Lang acknowledged cooperation and data sharing among the services was improving, but said the setup inevitably has gaps. He also urged legislators to reverse laws granting espionage targets, even abroad, the same constitutional rights as German citizens.

“Intelligence agencies are a tit-for-tat business,” he said. “If you’re not able to gather information, then your partners will not trade with you.”

Mr. Lange’s current worry is that Russian spies are seeking information on weapons or training for Ukrainian soldiers. Already, suspected Russian operatives have been found near military training sites in Germany.

Last month, Poland said it uncovered a Russian spy ring that had hidden cameras on rail lines in the southeast of the country, a major transit route for arms shipments to Ukraine.

But some lawmakers in Germany wonder whether concerns over Russia’s spies have strayed too far from a problem within their own walls: Members of the far-right Alternative for Germany party, whose leaders were frequent guests at the Russian Embassy, hold seats in some of the most important parliamentary committees, from foreign affairs to defense.

Mr. Grundl fretted over the fact that just last week, those far-right colleagues sat on a parliamentary committee while a secret topic was discussed.

“They are sitting in there, and they have the best connections to Moscow,” he grumbled. “That’s the bigger headache to me: the enemy within.”

Christopher F. Schuetze contributed reporting.