For various reasons--human compassion, border control, protection of Vietnamese ethnic groups, geopolitical maneuvering, etc--Vietnam invaded Cambodia to put an end to the violent Khmer Rouge regime, installed a friendly government, and ended up in a protracted guerilla war w/ the Khmer Rouge, who would stage attacks from Thailand. In a way I guess it was sort of Vietnam's Vietnam.
It's been awhile since I read the political history, but IIRC Thailand tolerated the Khmer Rouge retreating into and camping along its border because Thailand and Vietnam were (and remain?) regional power rivals. They avoided direct conflict but were happy to poke a stick in the other's eye.