To prevent the horde invasion you have to kill the witch that lives in the Infected forest, so that nobody could summon zombies. Until a new witch settles down in the forest, the horde will not appear. However, that will not stop the mob of zombies that has already advanced towards your base.
In addition to this, you can make a totem out of the witch's head and as long as the totem is on fire, the zombie horde will stay away from your home base.