WASHINGTON—President Trump on Thursday threatened to deploy the military and close the southern border if Mexico doesn’t stop an “onslaught” of Latin American migrants passing through its country from reaching the U.S.

On Twitter, the president blamed Democrats for what he described as “weak” immigration laws that have allowed undocumented migrants to enter the U.S. The Republican-controlled Senate and House this year rejected multiple immigration bills, including one backed by the president that would have combined border-security...