The 24-year-old, who is from Copenhagen, was arrested in April immediately after making the purchases and then placed in detention.
Danish intelligence, which says it has foiled several attacks in recent years, lists the terror threat against the country as serious.
“We believe that the firearm that the man bought would have been used to carry out a terror attack in Denmark or abroad,” prosecutor Lise-Lotte Nilas said in a statement without giving details about the eventual target.
“He failed because he was arrested immediately after the purchase.”
The man could be imprisoned for more than four years if found guilty.
The prosecutor's office is also pushing for him to be stripped of his Danish citizenship, deported and permanently banned from entering Denmark.
In another case, the Danish and German authorities said on Friday they foiled a possible jihadist attack in their two countries.