Non-mining full nodes cannot prevent a 51% attack, but they are essential in preventing other attacks.
In particular, full nodes verify that the chain produced by miners is valid. This means that no coins are transferred without proper authorization from their owner, that no new coins are being created out of thin air (except for those permitted by the inflation schedule), and a few other things.
Full nodes are what keeps miners honest. To anyone who verifies incoming transactions themselves using a full node ("economically relevant full node"), it guarantees that the chain is valid. Miners have no way to cheat those (apart from a 51% attack, see further), and as a result, they have no incentive to produce blocks that violate the rules, as such blocks will be dropped on the floor and ignored by full nodes. To anyone not running a node themselves, the knowledge that a sufficient number of other independent parties are running full nodes helps, because hopefully those parties are important enough that miners wouldn't want to waste their money creating an invalid block they would detect.
Bitcoin's security is based on auditability, not trust. You know the chain, in its entirety, is valid, because you're able to independently verify that it is.
Unfortunately, there is no way to verify which of two conflicting (but otherwise valid) transactions is the "real" one without a central clearinghouse that blesses one of the two. This is called the double spending problem, and it is the reason why we need miners: a decentralized clearinghouse that anyone with the right hardware, even anonymously, can join. Producing blocks costs money for them, and they're only paid if the network of full nodes accept their blocks. This is why they're incentivized (but not forced) to produce blocks that satisfy the rules, and build on top of each other's blocks.
But it is important to see that the 51% attack is the exception here. For almost every rule in Bitcoin, full nodes verify everything, and there is no way they can be fooled. The only thing that cannot be verified independently is double spends, which leads to a 51% attack if exploited (but the theory is that this would be expensive for miners so not economical; furthermore, if miners aren't doing their job well, others are incentivized to become a miner themselves).