I would say something like, “Hey, that’s my friend you’re talking about.” Not in an angry or accusative tone, but with an undertone that says “leave off, please.”
I was in a situation where a group of women were taking a verbal chainsaw to my close friend’s husband, and she wasn’t there. I have never been so uncomfortable- their malice and anger was disturbing and it was like they were one-upping each other on how ugly they could make this guy. I defended him a few times before I excused myself and left the gathering. When I wouldn’t return to their monthly rip-sessions, I became one of the people they hung on the meat hook to claw into (and was there for 4 years)... but that was perfectly fine, even though it hurt, because I was THRILLED to not be like them.
I told myself that over and over that I was not like that and joining them would slowly turn me into them. In the end, I had the perfect peace of mind when I was around my friend and her husband that I was a true and honest friend (and never told them).