The Republican-controlled US Senate has approved a bill to send aid to the border with Mexico, as the image of a drowned migrant family shocked the US.
It earlier rejected a rival aid bill from the Democratic-led House of Representatives imposing restrictions on US immigration agencies.
Lawmakers in both chambers now face pressure to reconcile the two bills.
Reports of migrant deaths, poor detention conditions and neglected child detainees have shaped the debate.
The funding bill battle comes amid outrage over photos showing a drowned migrant father and daughter at the US-Mexico border, and days after reports emerged of detention facilities where migrant children were being held in "horrific" conditions.
On Wednesday, President Donald Trump reacted to the outcry, saying Democrats wanted open borders, "and open borders mean people 'drowning in the river'".
The Democrats should change the Loopholes and Asylum Laws so lives will be saved at our Southern Border. They said it was not a crisis at the Border, that it was all just “manufactured.” Now they admit that I was right - But they must do something about it. Fix the Laws NOW!— Donald J. Trump (@realDonaldTrump) June 26, 2019
But a senior House Democrat said their bill was needed to counter the administration's policies.
"The president's cruel immigration policies that tear apart families and terrorise communities demand the stringent safeguards in this bill to ensure these funds are used for humanitarian needs only - not for immigration raids, not detention beds, not a border wall," said House Appropriations Committee chairwoman Nita Lowey, quoted by the Associated Press.
Republican leader Mitch McConnell had called House Democrats "consistently uncooperative and uninterested in anything except political posturing", after the lower chamber approved its own $4.5bn (£3.5bn) border aid bill on Tuesday.
"The Senate has a better and more bipartisan way forward," he said ahead of the vote. "No poison pills; just a clean bill to provide the emergency appropriations the White House requested two months ago."
Lawmakers will need to finalise legislation on aid funds before they take a week-long recess next week.
There are also concerns that border agencies will run out of money soon.
Speaker of the House Nancy Pelosi told reporters earlier that the Senate bill would not get through the House.
"There's some improvements that we think can be reconciled," she said. Mrs Pelosi had also discussed changes to the bill with President Donald Trump on Wednesday.
The two chambers will have to agree on a final version of legislation to send to Mr Trump to sign into law. The president had threatened to veto the House version of the bill before the vote.
What are the two bills?
Both of the bills included stipulations regarding migrant care and prohibit the use of the funds to build a border wall.
However, the Senate bill offers Pentagon funding and fewer rules on how agencies can appropriate the funds.
The House version, which passed on Tuesday along party lines in the Democratic-controlled chamber, contained more specific rules about standards for care and how money can be used.
The bill was toughened up after some Democrats expressed concern over providing extra funds for agencies involved in the current situation, including those enforcing President Donald Trump's "zero tolerance" policy which had last year led to migrant children being separated from their parents.
The Senate bill passed 84-8 with most Senate Democrats voting in favour of the bi-partisan legislation.
The House bill failed by a 37-55 margin, with three Democratic Senators joining Republicans in voting against it.
What's been happening at the border?
The congressional showdown follows outcry over humanitarian conditions at the border.
Several bodies, including those of babies and children, were discovered in recent days, as some migrants opted to try and cross into the US illegally, avoiding the formal immigration system.
A photograph of a father and his daughter lying face down in the water of the Rio Grande river has also shocked many. In the photograph, two-year-old Valeria has an arm wrapped around her father, Óscar Alberto Martínez Ramírez, as both lie dead close to shore.
Published by the Associated Press on Tuesday, it has drawn comparisons to the photo of young Syrian boy Alan Kurdi, who became a symbol of the human cost of the war in Syria.
Amid a major public outcry about the conditions facing migrant children, Customs and Border Protection acting commissioner John Sanders said he would be stepping down.
The acting director of Immigration and Customs Enforcement, Mark Morgan, is set to replace him.
Why is there a political crisis about the border?
Mr Trump's "zero tolerance" policy was announced in early 2018. By prosecuting adults who crossed the border illegally, it had the effect of separating children from their parents.
Despite a court order requiring families to be reunited and an end to separations last year, hundreds remain in government shelters, to which the public - including journalists and rights activists - had little access.
Lawyers were recently given access to one facility in Clint, Texas, by a judge. They reported appalling conditions inside, in which children under 10 were caring for infants, and massive overcrowding.
Children were "locked up in horrific cells where there's an open toilet in the middle of the room" where they ate and slept, one of the lawyers told the BBC.
Separately, a legal argument from the government that access to soap and a toothbrush were not necessarily "required" has drawn much criticism.
Five questions about the border crisis
Where do these people come from?
Traditionally large numbers of Mexican economic migrants have declined, replaced in part by a surge in families with children from Central American countries - particularly Guatemala, Honduras, and El Salvador.
Why are they fleeing?
Many of these families are fleeing extreme poverty or the risk of gang violence. The UN refugee agency calls the three countries "some of the most dangerous places on Earth" - but the US attorney general has decreed that gang violence does not usually qualify someone for asylum.
Why are there still separated children?
Although the separation of migrant families was officially halted in June 2018, the New York Times reported that 700 families had been separated in the year since via "loopholes" in the court order - when parents have a criminal conviction or a disease, or when it is an aunt, uncle, or sibling accompanying the child. Some parents may be children themselves.
How many people cross the border?
US Border Patrol says it has made 593,507 "southwest border apprehensions" since October 2018. Last month, 132,887 people were stopped - including 11,507 unaccompanied children and 84,542 travelling in families.
How many people have died?