A federal judge has ordered that US immigration agents can no longer separate parents and children caught crossing the border from Mexico illegally.

Dana Sabraw, a district court judge in San Diego, granted the preliminary injunction on Tuesday, which set a hard deadline for US immigration to work to reunite those families that have already been split up within 30 days.

The court also ruled children younger than five must be reunited with their families within 14 days.

It is not yet clear how border authorities will meet the deadline.