The arrest of the men had been widely reported and the suspects named in Italian and international media, with claims that they belonged to a jihadist cell with links to Isis and Al-Qaeda.
A 23-year-old Afghan and 24-year-old Pakistan national have now been released after being held for two days. Italy's interior minister Angelino Alfano had on Tuesday hailed the arrests as a success for Italy's counter-terrorism work, but the men's lawyer has now described it as a "blunder".
Lawyer Adriano Pallesca said: "The case has been blown out of proportion, a blunder due to a mere photo of a person with a toy weapon in their hand," according to Rai News. He added that the judge had made the correct decision in ruling that the evidence was not strong enough to support such a severe crime as terrorism.
A preliminary judge (gip), Francesco Agnino, confirmed the mens' arrests for involvement in trafficking migrants but turned down the request from prosecutors to keep them in police custody.
At the time of the arrests, prosecutor Roberto Rossi told La Repubblica that the pair were part of a cell planning attacks against "government and military targets, public institutions, international companies and civilian targets", having found photos of strategic targets including hotels, airports, and the Colosseum, as well as the photo of the 23-year-old holding the toy gun in a supermarket.
Police also said they were unable to access a locked iPhone which was thought to contain additional evidence.
Pallesca rebuffed the claims, saying that the evidence currently available does not show involvement in international terrorism, and consists of "videos and photos taken during moments of leisure".
He added that his client "cried a lot and emphasized that in Afghanistan he was persecuted by the Taliban, so he did not see a reason to commit terrorist acts here, in the country which welcomed him."
A third suspect, a 29-year-old Afghan national, remains in police custody, charged with aiding and abetting the trafficking of illegal immigrants.
Meanwhile, two other men connected to the case are still wanted by police in connection with charges of terrorism.