KURIGRAM, Bangladesh—India and Bangladesh swapped land along their border, ending a decadeslong dispute that had left more than 50,000 people virtually stateless.

The South Asian nations share a highly irregular, 4,000-kilometer border, where because of a quirk in their shared history small pockets of land belonging to each had been surrounded completely by the territory of the other.

At...