An antivirus software basically acts as a filter between you and the internet.
It doesn't allow you to download files that contain code that might harm your device.
But the current generation anti-virus softwares also have extra functions like:
-scanning your computer for existing virus or Trojan.
-preventing unknown devices to send and receive packets from your device (basically prevent MITM attacks)