Hey there. First of all, I want to say it's really awesome that you stood up to your friends and defended the person they were making fun of. Peer pressure, especially among young people, can make it hard to speak out against the group when something transphobic, homophobic, racist, ableist, etc. is said. The fact you stood up not just for your beliefs, but for what's right, speaks volumes about your character. So thank you.
It's hard to leave a friend group, especially if it's been an established one for so long. But these are not the type of people you want to be friends with. It's not just the person(s) who made the comment; people who are complacent, and say nothing when these kinds of things happen, are just as much at fault. They are all part of the problem.
I think how you want to leave your friend group is up to you; I am not sure there's a "best" way to do it. You could make a public statement as to why you are leaving, and essentially cut them off all at once. You could slowly just fade out of conversation. There's options. As for your two friends you like, maybe you can talk to them. Let them know you're feeling upset about what's going on and you want to cut ties. I don't see why you can't be friends with them just because they're a part of the group and you aren't anymore. I think it can all work out with clear communication.
Good luck, and
PM me if you need anything.