To keep a villager from moving, speak to them when they mention leaving and choose a negative response such as “No, don’t go” or “Aww.” Repeating this over several days may make them reconsider.
Sending them kind letters can also help improve your relationship and make them more likely to stay.