If there is a mob at the portal, or one appears while you are closing it, you do not have to fight the mob (assuming you can avoid it).