BUDAPEST—Hungary has reached an agreement with the Czech Republic, Poland and Slovakia to jointly patrol its southern borders to deal with the rising number of migrants from war-torn areas of the Middle East and Afghanistan trying to cross its frontiers.

At the same time, the government in Budapest is considering closing its border with Croatia and is working to fence off its neighbor to prevent migrants from entering its territory that way. In August, Hungary completed a razor-wire fence along its 110-mile border with Serbia,...