The bill was rejected in a 121-301 vote, which was short of about 218 votes needed to pass. No Democrats voted for it.
Republican House leaders worked Tuesday to shore up last-minute support for the immigration bill before Wednesday's vote.
Under the proposal, children who cross illegally with parents or adult guardians would no longer be separated -- an issue that stirred significant controversy last week and led to a presidential order and federal court ruling.
The bill would have required children to be released after 20 days, still apart from parents who continued to be detained. Unaccompanied children would be returned to their home countries.
Included in the bill was nearly $25 billion for the U.S.-Mexico border wall, a project sharply opposed by Democrats but required by Trump, he said, for his signature.
The bill would have also allowed a path to citizenship for 3.6 million Deferred Action for Childhood Arrivals recipients, or "Dreamers." Democrats, though, said the bill would have made that path more difficult.
The Cato Institute, a Libertarian think tank, estimated eligibility restrictions in the bill would only result in about 12 percent of Dreamers becoming U.S. citizens.
A group of bipartisan senators is also working on a compromise bill to address family separations. The group includes Republicans, Sens. Ted Cruz, R-Tex., and Thom Tillis, R-N.C., and Democratic Sens. Dianne Feinstein, D-Calif., and Dick Durbin, D-Il.
Last week, Republican leaders in the House rescheduled the vote on the Ryan's moderate version after rejecting a more conservative proposal.