Here's a summary of a great article by Rebecca Watson called "How To Stop Gossiping."
1. Define gossip. I've always like Dave Ramsey's definition of gossip: "Discussing anything negative with someone who can't help solve the problem." Maybe your definition of gossip would also include positive comments of someone who isn't around. Determining how you define gossip establishes boundaries.
2. Redirect conversation. Change the subject with someone who wants to gossip with you. If possible, connect the dialogue to something similar; it makes it less obvious. Once the conversation has been steered away from gossip, it becomes more difficult to return there.
3. Stay quiet. Not responding at all can be a very effective way to stop gossip. Most people get the message.
4. Empathize with the subject of gossip. Turn the conversation to yourself or the person with whom you are talking. Nothing stops back-talk faster than recalling your own flaws. We’ve all got them.
5. Call it what it is. If the other techniques haven’t worked, this one definitely will. You can soften it a bit by saying something like, "I'm trying to stop gossiping."