A device thrown by a counterprotester during an anti-Islam demonstration in New York City was an improvised explosive.