Momentum has grown to restrict toy guns over the past year, set off in part by the death of Tamir Rice, a 12-year-old boy who was playing with a toy gun when he was shot by a police officer in Cleveland in November. In 2015, lawmakers in Florida, Indiana, Massachusetts, Nebraska, New York, Ohio and Washington introduced legislation to create or amend toy gun laws, according to the National Conference of State Legislatures. Half a dozen states, as well as Puerto Rico and Washington, D.C., already have laws on the books, according to the organization.
Mr. Schneiderman's office said the enforcement actions have two goals: cut down on crimes that involve toy guns, like robberies, and help prevent split-second mistakes by the police that can end in death. Since 1994, there have been at least 63 shootings in New York State because of toy or imitation guns, according to the attorney general's office, at least eight of them ending in fatalities.
Read MoreInside the millionaires' gun club
"One of the problems we have is there are so many guns in our society that it makes people jumpy, including law enforcement," said Leah Gunn Barrett, the executive director of New Yorkers Against Gun Violence. "Even the most well-trained people can make mistakes, and we want to minimize the chance of that happening."
Federal law requires toy guns to have an orange strip near the tip, but more restrictive measures can vary by state and city. New York State law prohibits the sale of black, blue, silver or aluminum toy guns, for example, while New York City is stricter: Imitation guns must be brightly colored, or translucent, among other restrictions.
The attorney general's office sent cease-and-desist letters to Walmart, Sears, Kmart, Amazon and a cluster of smaller toy websites in December. As part of the settlements, the retailers have agreed that they will sell only toy guns that comply with the city standard throughout the state.
Most of the illegal toy gun sales came through third-party sellers on Amazon, Mr. Schneiderman's office said. But Walmart will pay the bulk of the civil penalties because it was found to have violated terms of a 2003 agreement to keep such products out of New York. While Walmart had not sold any illegal toy guns in its stores, consumers in New York purchased 149 of them through its website.
Since 2003, the retailer has successfully blocked the sale of some toy guns into New York, according to Randy Hargrove, a Walmart spokesman, but three models had made it through.
Read MoreGun makers' big bet on women pays off
"Once the New York attorney general expressed concern with certain items sold at Walmart.com we blocked the shipment of those items into the state," Mr. Hargrove said in an email, adding that the company had revised its policies to prevent toys from slipping through in the future. "We are pleased we were able to resolve this matter, along with several other retailers."
A spokesman for Sears Holdings, which also owns Kmart, said in an email that the company was "pleased" to resolve Mr. Schneiderman's concerns. A spokesman for Amazon did not respond to requests for comment.