Police and other security forces detained the man on Saturday in Bernau, a town near Berlin, and searched his home there, federal prosecutors said.
Prosecutors said the man was a Libyan national identified only as Omar A.
“He intended to carry out a high-profile attack with a firearm against the Israeli embassy in Berlin,” the statement said.
In his planning, the statement added, “the accused exchanged information with an IS member in a messaging chat.”
Security forces also searched the home of another person believed to be a witness and not a suspect, the prosecutor’s statement said.
Interior Minister Nancy Feiser said German security authorities had “struck in time to thwart any plans to attack the Israeli embassy in Berlin”.
“This shows that protecting Jewish and Israeli institutions in our country is vital and of utmost importance to us,” she added.
The man appeared on Sunday before an investigating judge at the country’s highest court, the Federal Court in Karlsruhe.
Israeli Ambassador Ron Prossor thanked the German security authorities “for ensuring the security of our embassy”, the German news agency dpa reported.
News of the case first came from the Bild newspaper, which reported that a heavily armed elite police unit had raided the man’s home in Bernau. It said German authorities acted after receiving a tip from an unspecified foreign intelligence agency.
“We are acting with the utmost vigilance and caution in view of the high threat of Islamist, anti-Semitic and anti-Israel violence,” Ms Feiser said.
According to Bild, the man is 28 years old, arrived in Germany in November 2022 and applied for asylum. DPA reported that his asylum application had been rejected.
Justice Minister Marco Buschmann also warned on Sunday of a “very serious” threat from Islamic terrorism in Germany. “Israeli institutions are particularly often targeted by terrorists,” he told dpa.
A sharp increase in anti-Semitic incidents has been reported in Germany since the October 7, 2023, attack by Hamas on Israel, which sparked the ongoing wars in the Middle East.