A similar policy will apply to Instagram, the company’s photo-sharing network, Facebook said. The policies announced today will be implemented over the next few weeks.

“We will remove reported posts that explicitly indicate a specific attempt to evade or help others evade the law,” the company said in a statement today. “For example, we will remove reported posts where the potential buyer or seller indicates they will not conduct a background check or are willing to sell across state lines without a licensed firearms dealer.”

New York Attorney General Eric Schneiderman and gun control groups have been asking Facebook to implement such restrictions. New York requires a federal background check for private gun sales and prohibits sales of some popular firearms, such as the AR-15. His office collected evidence that some website users were willing to sell guns without background checks or otherwise violate the sales restrictions of states with tougher gun control laws.

Mayors Against Illegal Guns, the group backed by former New York Mayor Michael Bloomberg, and Moms Demand Action have been pressuring Facebook to address the issue. Petitions from Moms Demand Action calling on Facebook to prohibit illegal gun sales had more than 230,000 signatures.

“Responsible social media sites know that it is in no one’s interest for their sites to become the 21st century black market in dangerous and illegal goods that place our families and communities at risk,” Schneiderman said. “I congratulate Facebook and Instagram for taking these simple, common sense steps to protect the safety and security of their users, and encourage other social media sites to follow their lead.”

Facebook said it will remove messages for buying or selling guns that indicate an attempt to evade the law. It also will issue advisories to users offering to sell “commonly regulated goods” — such as guns, tobacco, alcohol and adults products — to obey relevant laws. It also will keep children from seeing such posts.

Under the stated policy, Facebook would allow a user in Texas to list an AR-15 for sale, since the gun is legal there, if it weren’t offered for sale in states where it’s illegal. But it would delete a similar post from someone in New York. It would, however, remove posts from any state in which the seller says the background check will be skipped, even if such checks aren’t required where the seller lives.

In her online petition, Shannon Watts of Moms Demand Action, had written: “There’s no way to stop a Facebook or Instagram user from potentially selling a gun to a felon, a domestic abuser or another dangerous person who would otherwise be prohibited from obtaining a gun.”

Acknowledging people can’t actually sell things to each other through its site, Facebook said many people and organizations use its free tools to promote commercial transactions.

“This is one of many areas where we face a difficult challenge balancing individuals’ desire to express themselves on our services and recognizing that this speech may have consequences elsewhere,” the company said.

The company said it already has systems in place to remove advertising that’s false and deceptive or violates its policies. It already prohibits ads for illegal drugs, tobacco products and prescription drugs.

There’s no way to know how many guns are sold via Facebook, because the transactions are actually completed offline, said John Feinblatt, chairman of Mayors Against Illegal Guns. But such sales have occurred. In Kentucky, for example, federal authorities in February charged an Ohio man with illegally selling a 9 mm pistol to a Kentucky teenager, a transaction that investigators say was arranged through Facebook.

Feinblatt noted that Google Plus and Craigslist already prohibit all gun sales. But he said there are “really virtual gun shows” online. His group issued a report in December showing 66,000 active ads on a popular gun sales website called Armslist, up 500 percent from two years earlier.

The report said 16 states and the District of Columbia require background checks for private firearm purchases.

Federal law prohibits gun sales to anyone under indictment or convicted of a crime punishable by a year in prison, fugitives, drug addicts, those who are adjudicated mentally defective, immigrants in the U.S. illegally, anyone dishonorably discharged from the military, anyone convicted of misdemeanor domestic violence or subject to a court order of protection after being judged at a hearing to be a physical threat to a partner or child. The FBI’s National Instant Criminal Background Check System lists people prohibited from buying guns.

Tom King, president of the New York affiliate of the National Rifle Association, acknowledged that Facebook is allowed to set its own rules, but he looks at the new restrictions “as a kind of limit on our First Amendment rights.” Although his group doesn’t sell guns, he questioned whether they could be blocked if somebody reports the Rifle & Pistol Association’s Facebook page anyway.

“This is something that could greatly get out of control very quickly,” King said.