(Read our story about Dick’s changing its firearm policy.)

The moves by the two companies came two weeks after 17 people were killed at Marjory Stoneman Douglas High School in Parkland, Fla., when a gunman armed with an AR-15-style rifle shot up the school. Edward Stack, the chief executive of Dick’s, said company leaders were “disturbed and upset” about what happened at the school and wanted to act.

“We love these kids and their rallying cry, ‘Enough is enough,’” Mr. Stack said in an interview earlier on Wednesday. “It got to us.”

The decisions by Dick’s and Walmart drew immediate — and passionate — reaction on social media, attracting both praise and outrage. Their changes were both symbolic and meaningful, thrusting the two major retailers into a contentious national debate on guns. They also came on the same day that President Trump appeared to buck his own party and embrace gun control, urging lawmakers to resurrect gun safety legislation that the Republican Party and the powerful gun lobby have long opposed.

Since the Florida school shooting, a number of major companies, including Delta Air Lines, announced they had ended their discount arrangements with the National Rifle Association. Other companies, including FedEx, said they would continue to offer discounts to members of the N.R.A.

The new policy by Walmart is the second change in recent years regarding the type of firearms and guns accessories sold in its stores. In 2015, Walmart said it would no longer sell high-powered rifles in the United States, but cited lower customer demand for the military-style rifles and not politics.