The prosecutor’s office in the southern city of Stuttgart confirmed on Thursday that the Syrian refugee was arrested on Sunday.
The 20-year-old man had failed to cross into Denmark a day earlier, they said.
Investigators believe he was planning to carry out an attack after discovering that he had obtained material which could be used to build weapons or bombs.
Spokesman Jan Holzner told the Reuters news agency that the suspect had been in Germany for some time but it was not clear when he entered the country.
Holzner did not identify the man and did not know whether the man had been granted asylum.
He had been living in a refugee shelter in southwest Germany.