A router will act as a firewall in the true sense of the word and it has been covered here before.
To compare, let's look at the standard PC>MODEM>Internet setup first. In this configuration, the modem is simply an interface between the PC and the Internet, and it's only purpose is to convert the data from the PC into a format that can be transmitted across the phone network and vice versa. It is effectively invisible. Your PC (generally) will adopt a public ip address leased from your ISP and actually becomes part of the internet. This also means that anyone else connected to the internet could, in theory, access your PC if it knew it's ip address.
By using a router, you actually separate your PC (or PCs) from the internet, which now form part of a private network (even in the case of a single PC). The router adopts the public ip address and will lease private ip addresses to the PC(s). The router becomes what is known as the default gateway and when a PC trys to access an ip address outside the private network, it will send it to the default gateway (router). The router stores details of the request (ie, where it came from and other identifying information) and sends it to the next router in the chain (your ISP). Eventually, a response comes back to the router, which looks up a table of stored requests and routes the information to the requesting PC. This technology is known as Network Address Translation (NAT). Now, if the router receives a response for which it has no request, it will drop the packets, effectively acting as a firewall.
So, in summary, it will only prevent incoming requests where there is no outgoing request.
If however, you have allowed a trojen to enter your machine (via email or download), it can generate outgoing requests, so NAT will not prevent this type of intrusion, which is why anti virus/spyware software is important. You could use a software firewall, such as zone alarm (or a more advanced dedicated hardware firewall, which can be expensive), which will alert you if an application is trying to access the internet. These have their uses, but need to be configured to be effective. Software firewalls can also mask the effects rather than remove them, so should be used with caution. If you use one, read the instructions and make yourself fully aware of how it works and then it will be useful.
I personally don't use software firewalls, but then i'm aware of the dangers and am well protected in other ways.
Routers can have other technology built in to perform more advanced functions and I suggest you do a google on SPI for more details. It's always worth checking the internet for reviews before you buy. I generally recommend Draytek routers for home use, but there are plenty to choose from.
This is a very simplistic view, but I hope it helps.