WASHINGTON — In the three weeks since three mass shootings left the country reeling, powerful pro-gun groups have sent President Trump a clear signal — don’t forget that we helped put you in the White House.

On Tuesday, the president made clear he was listening. He reversed course and backed away from potential new restrictions on gun sales that he had embraced days after the massacres in California, Texas and Ohio, suggesting less controversial responses like more money for mental health care and stiffer prosecution of federal gun crimes.

“A lot of the people who put me where I am are strong believers in the 2nd Amendment, and I am also,” Trump told reporters in the Oval Office.

Then he argued that any efforts to restrict gun sales would inevitably lead to confiscation of privately owned weapons from law-abiding citizens, although no one has proposed that drastic remedy on Capitol Hill.

“They call it the slippery slope,” he said. “And all of a sudden everything gets taken away. We’re not going to let that happen.”

Trump also retreated from his previous call for more aggressive background checks of people who buy firearms.

“We have very, very strong background checks right now,” he said.

The about-face followed a familiar pattern for Trump, a native New Yorker who lacks a personal affinity for guns but has championed gun rights since entering politics. Before he ran for president in 2015, he supported restrictions championed by Democrats, but now he fears upsetting his hardcore Republican supporters — especially as he heads into what polls indicate will be a difficult reelection race.

“Donald Trump has looked into the abyss of destroying his base and decided that isn’t something he wants to do,” said Michael Hammond, legislative counsel for Gun Owners of America, an advocacy group based in Virginia.

Although presidents often are forced to disappoint their most loyal fans when cutting political deals in Washington, Trump has been particularly wary of alienating his base. His latest retreat reflects not only his desire for adulation from the crowds that pack his rallies, but also a recognition that turning out his passionate supporters in 2020 may be a better route to a second term than trying to attract undecided voters.

“Without the support of gun owners, it’s unlikely that Donald Trump would ever have been elected,” said Adam Winkler, a UCLA law professor who researches politics and gun laws. “He needed those votes and he got them.”

Trump initially appeared open to strengthening gun laws after recent shootings echoed across the nation.

On July 28, three people were shot to death at a garlic festival in Gilroy, Calif. Then, on Aug. 3, a gunman opened fire at a Walmart in El Paso, killing 22 people in an attack that investigators say targeted Mexicans. The next day, nine people were killed outside a bar in Dayton, Ohio.

As the horrors sunk in, Trump addressed the nation from the White House on Aug. 5. He said he supported “red flag” laws that would allow law enforcement to temporarily remove guns from people who courts determine to be an imminent threat to themselves or others. More than a dozen states, including California, already have such laws.

“We must make sure that those judged to pose a grave risk to public safety do not have access to firearms and that if they do those firearms can be taken through rapid due process,” Trump said.

Four days later, Trump went further, telling reporters that “we have to have very meaningful background checks” before gun sales. He even talked with Sen. Christopher S. Murphy (D-Conn.), an outspoken advocate for universal background checks and other reforms since the Sandy Hook Elementary School shooting in his state in 2012.

“He expressed support for working together with Republicans and Democrats to come up with a background checks bill that can pass the Senate and save lives,” Murphy said at the time.

After that, pro-gun groups began blanketing Capitol Hill and the White House with emails and phone calls, demanding lawmakers block any new restrictions. The National Rifle Assn., which usually hunkers down after mass shootings, publicly criticized what it called a push for “sound-bite solutions,” and its chief executive, Wayne LaPierre, spoke to Trump on the phone.

Activists argued that while public opinion polls show background checks for gun sales are extremely popular, such restrictions won’t stop mass shootings, which typically are committed by people who buy guns legally. The NRA has tried to point the president toward policies that could satisfy his desire to take some action worthy of a Rose Garden ceremony, without upsetting his pro-gun supporters.

They also called for stricter enforcement of existing laws, pointing to a standoff in Philadelphia last week where six police officers were wounded with an assault-style rifle. The suspect was a felon and should not have had access to a gun. He was later charged with attempted murder.

Trump tweeted about the shooting, saying “must get much tougher on street crime!”

Lobbying the president has required navigating Trump family politics. Ivanka, the president’s older daughter and a White House advisor, backs increased gun restrictions. So pro-gun groups turned to Donald Jr., the president’s eldest son and an avid hunter, to push back.

“The president’s son has a lot stiffer spine on the gun issue than the president, and I think a better handle on it,” said Dudley Brown, president of the Colorado-based National Assn. for Gun Rights, another advocacy group.

Pro-gun groups were hesitant to declare victory this week, since lawmakers still could take action when Congress returns from its August recess next month.

Sens. Joe Manchin III (D-W.Va.) and Patrick J. Toomey (R-Pa.) have written a bipartisan measure to expand background checks, and Sen. Lindsey Graham (R-S.C.), a Trump ally, is pushing “red flag” legislation.

But the momentum for such change seems to have dissipated. Trump said little about gun control Thursday in Manchester, N.H., in his first political rally since the shootings. “It’s not the gun that pulls the trigger, it’s the person holding the gun,” he told the crowd, which gave a rapturous response.

Trump’s critics cited a similar cycle after a gunman killed 17 students and teachers at a high school in Parkland, Fla., in February 2018. During a televised round table with bipartisan lawmakers, Trump voiced support for new restrictions and insisted that the NRA had “less power over me.”

But no new gun laws were passed, and at this point, it’s hard to see Congress passing, or the president signing, any new legislation.

“These retreats from President Trump are not only disappointing but also heartbreaking, particularly for the families of the victims of gun violence,” Senate Minority Leader Charles E. Schumer (D-N.Y.) said in a statement.

John Feinblatt, president of Everytown for Gun Safety, which pushes for stiffer gun laws, said Trump should be more aggressive because the NRA, which has faced internal power struggles and a scandal over lavish spending by its leaders, “has never been weaker.”

“Voters across the political spectrum are demanding change — and politicians who ignore them today will suffer the consequences in 2020,” he said.