WASHINGTON — For President Donald Trump, cracking down on illegal immigration is good politics, but separating families in the process is not.

Trump signed a slapped-together executive order after days of protests from across the political spectrum, including Republican lawmakers who expressed concerns about their re-election prospects, according to current and former administration officials.

Pressure also came from within his own family. Ivanka Trump had been working with top GOP lawmakers — including Senate Majority Leader Mitch McConnell of Kentucky, House Majority Leader Kevin McCarthy of California and Sen. Susan Collins of Maine — to find a way out, said a White House official who spoke on condition of anonymity to discuss sensitive discussions within the first family.

More from USA Today:

Trump signs executive order on immigration, but says 'zero tolerance' will continue

What's changed after Trump's immigration order: For families, for the military and for Congress

Trump signs executive order to end immigrant family separations: What we know

First lady Melania Trump also urged the president to change course. The first lady made a public statement Sunday urging "both sides" to come together on a solution to the crisis. But as media coverage intensified in recent days, she appealed to her husband to act alone if necessary, said another White House official.

"Ivanka feels very strongly. My wife feels very strongly about it. I feel very strongly," Trump said Wednesday after signing the executive order. "I think anybody with a heart would feel strongly."

While defending his "zero tolerance" immigration policy in recent days, Trump also expressed frustration with the televised images of children being taken from their parents and being detained in cage-like holding cells, according to current and former officials; some spoke on condition of anonymity to discuss private conversations.

Trump voiced his concerns during a meeting with House Republicans on Tuesday, telling them at one point that his daughter Ivanka had questioned the policy. "We have to take care of these separations," he said.

Trump believes that dissatisfaction with illegal immigration proposals propelled him to the White House, and that the issue is essential to his base of voters who believe that migrants are taking American jobs and committing crimes.

The immigration issue polls well, advisers said, but taking children from their families does not.

In short, they said, Trump wanted to take the separated families issue off the table.

The White House also acknowledged the worries of congressional Republicans seeking re-election.

Despite high political stakes over the family separations, the meeting at the Capitol Tuesday night followed the pattern of most meetings between the president and Republican lawmakers. It was heavy on what the president views as his accomplishments and included far less about what has been driving the conversation on Capitol Hill lately — immigration.

The president spoke for most of the time and there was no push-back from members on what was happening at the southern border. The only tense moment came when the president made fun of Rep. Mark Sanford, R-S.C., a Republican critic of the president's who lost his primary last week.

Many lawmakers brought their families to the gathering. On their way out they said they were optimistic the president backed the legislation House Speaker Paul Ryan, R-Wis., has been pushing, even if Trump never actually said he endorsed it. That legislation would address the family separations.

For a president who never apologizes and rarely backs down, the order was an extraordinary climax to weeks of heart-wrenching news coverage of crying children being held in federal detention centers, separated from their parents after crossing the U.S.-Mexican border.

While defending his "zero tolerance" immigration policy in recent days, Trump lashed out at Democrats for obstructing his hard-line immigration proposals and the news media for emphasizing the plight of immigrant children and not the crimes committed by immigrants who enter the country illegally.

"The Fake News is not mentioning the safety and security of our Country when talking about illegal immigration," he tweeted Wednesday. "Our immigration laws are the weakest and worst anywhere in the world, and the Dems will do anything not to change them & to obstruct want open borders which means crime!"

But privately, Trump also expressed frustration with the televised images of children being taken from their parents and being detained in cage-like holding cells, according to current and former officials; some spoke on condition of anonymity to discuss private conversations.

Adding to the pressure: A protest outside a Mexican restaurant in Washington where Homeland Security Secretary Kirstjen Nielsen was dining Tuesday night, underscoring how untenable the issue ultimately became despite the public bravado that the administration tried to show.

Trump supporters touted the action as a limited, temporary fix that tries to strike a tough-but-compassionate balance — mollifying critics while still appeasing his more conservative base.

Voters oppose the family separation policy 66 percent to 27 percent, according to a Quinnipiac University National Poll released Monday. But Republican voters support it, 55 percent to 35 percent.

"Obviously the images are something that nobody wants to see," said former White House press secretary Sean Spicer.

"If they can fix this quick and get really strong on the border in the long term, there is the potential for upside," he said. "Right now, the imagery is not helpful to the party in power."

But even as he attempts to tamp down protests from the left and center, Trump is signaling to his supporters that he remains as committed as ever to his pledge to crack down on illegal immigration.

Boris Epshteyn, chief political analyst at Sinclair Broadcast Group and former special assistant to Trump, said the president "will continue to be tough on illegal immigration, which is important to him and his base, while also being humane."

On Capitol Hill, GOP lawmakers seemed to be surprised by Trump's move — but stressed that it doesn't solve all the problems at the border.

"If it's what I think it is, which is to keep families together, that's good," said Sen. Rob Portman, R-Ohio. "But you still have to have the infrastructure in place to make this work right. You have to be able to adjudicate these cases quickly, so you need more judges, you need more family detention facilities.

"We need to have a system in place where it can be handled properly," he said.