WASHINGTON — The United States is preparing to shelter as many as 20,000 migrant children on four American military bases, a Pentagon spokesman said on Thursday, as federal officials struggled to carry out President Trump’s order to keep immigrant families together after they are apprehended at the border.

The 20,000 beds at bases in Texas and Arkansas would house “unaccompanied alien children,” said a Pentagon spokesman, Lt. Col. Michael Andrews, although other federal agencies provided conflicting explanations about how the shelters would be used and who would be housed there. There were reports of widespread confusion on the border.

It was unclear whether the military housing would also house the parents of children in migrant families that have been detained, and officials at the White House, the Defense Department and the Department of Health and Human Services said on Thursday that they could not provide details.

The Pentagon announcement followed Mr. Trump’s executive order on Wednesday to keep families together after they illegally cross the Mexican border into the United States. The order called for detaining families at the same location.