Terraria, pirate invasion

This happened to me as well and sadly there isn't any easy way out of it. Moving your spawn will help stop you from having to fight pirates as soon as you spawn in but that won't stop the pirate invasion.

It's a long process but even with only the Night's Edge you can kill a few pirates at a time. After you kill enough and the invasion ends you just need to kill the last few left. One thing to remember is not all of the pirates can open doors, so if you ever need a minute to heal you can always run into your house for a little while.