You are not permitted to download, save or email this image. Visit image gallery to purchase the image.
The man, Stephan B., modelled Wednesday's attack on a shooting spree at mosques in the New Zealand city of Christchurch, in March this year in which 51 people were killed.
He wanted to kill as many people as possible in the synagogue in the eastern city of Halle, the prosecutor said.
Dozens of people were at the synagogue on Yom Kippur, the holiest day of the Jewish year, when the gunman tried to blast his way in - only to fail to breach the solid locked gates.
"What we experienced yesterday was terrorism. According to our findings, the suspect Stephan B. aimed to carry out a massacre," federal prosecutor Peter Frank told reporters.
"Stephan B., a man who was influenced by scary anti-Semitism, xenophobia and racism, was heavily armed," Frank added. "He armed himself with many weapons, some possibly self-made, and had a large quantity of explosives."
Investigators found 4kg of explosives in his car.
In a video of more than 30 minutes that the attacker live-streamed from a helmet camera, he was heard cursing his failure to enter the synagogue before shooting dead a woman passer-by in the street and a man in a nearby kebab restaurant.
Two other people were injured but not critically.
"Stephan B. wanted to be copycat in two senses," said Frank. "He wanted to mimic similar acts that happened in the past, and he also wanted to incite others to copycat his acts."
Justice Minister Christine Lambrecht said right-wing extremism "is one of the biggest threats facing us". She vowed to get tougher on online platforms if they carry threats or material that incites hatred.
Earlier, Chancellor Angela Merkel said Germany must crack down on hate, violence and hostility.
"I am, like millions of people in Germany, shocked and dejected by the crime that was perpetrated in Halle yesterday," Merkel said to loud applause in an address to a trade union congress in Nuremberg.
A military source said Stephan B. had done military service, but received no special training. His full name cannot be published under German privacy laws.
The suspect would appear before federal judges on Thursday, accused of two counts of murder, Frank said. Questions remained about how he armed himself and whether he had any accomplices.
Most Jewish institutions in large German cities have a near-permanent police guard due to the threat of anti-Semitic attacks by both far-right activists and Islamist militants.
Josef Schuster, president of the council of Germany's 200,000-strong Jewish community, criticised police for not being present at the synagogue in Halle.
"If police had been stationed outside the synagogue, then this man could have been disarmed before he could attack the others," Schuster told Deutschlandfunk public radio.
In the event, the synagogue's solid locked gates and high walls provided ample protection against the attacker's seemingly improvised weapons.
Schuster said that while it was normal in his experience for all synagogues to have police guards during services, this appeared not to be the case in the state of Saxony-Anhalt, where Halle is located.
However, the head of Germany's police union was sceptical about providing that level of protection.
"We'd have to guard every synagogue, every church, every mosque, every holy place in Germany around the clock, so I don't know if this was a mistake or if this really couldn't have been foreseen," Oliver Malchow told ARD public television.