WASHINGTON—President Donald Trump directed his administration on Wednesday to try to detain asylum-seeking families together, a reversal after weeks in which he insisted he had no choice but to separate children and adults who cross the border.

On Capitol Hill, lawmakers wrestled with demands that they take action of their own to end family separations and pass broader immigration legislation, ahead of contentious votes on a pair of bills scheduled for Thursday.

In an executive order, Mr. Trump said families seeking asylum should be detained together when “appropriate and consistent with law and available resources.”

He kept in place the administration’s “zero tolerance” policy, instituted earlier in the spring, of prosecuting adults who attempt illegal entry into the U.S. That policy provoked a political outcry when it led to the separation of thousands of children from adults who were arriving at the southern border.

“We’re going to keep families together, but the border’s going to be just as tough as it’s been,” Mr. Trump said of the order at a campaign-style rally Wednesday night in Duluth, Minn.