She's on the borderline between "still young and doesn't realize what she's saying" and totally understanding what she's doing. It's a delicate place to be, and you are right to recognize this and see that you need to work on this--now.
By about age 10, there are kids who are definitely becoming the "alpha girls and boys" and kids who become the scapegoats and kids who don't care either way and kids who aren't in any "category"...and so forth. So what she's doing, at nine, is worrying; she may be heading into alpha territory. She may not be fully conscious that she's acting controlling, but that is indeed what she is doing with this one friend. She didn't have to mention the other sleepover at all (the one to which friend wasn't invited) but did so -- and the "it wasn't great, it was for third graders" comment doesn't really change the fact that she was alerting her friend to the fact that "I was there and you weren't invited." The situation with "others are coming who don't like you but I will protect you" is even more controlling -- she's simultaneously belittling this friend and then offering her protection. It's alpha territory: You're not as cool as the rest of us but I am your source of protection so stick with me. She may not be doing it intentionally --she's not sitting there consciously thinking "I'm going to keep Friend sticking to me by telling her others don't like her..." -- but she's doing it nevertheless.
You can do a few things. Consider talking to the school counselor (just you, without your daughter there) and asking for ways to help her learn more empathy about these social situations. Ask for some specific scripted things to discuss with her. Also talk to the children's librarian at your local library; the librarians should be able to direct you to some good books for her age that will help. The American Girl books, which are good for age 9, cover a lot about how kids interact; you might need to look through them to find the ones that will interest and speak to her best.
For yourself, read the book "Queen Bees and Wannabes" which talks about older kids but is very appropriate at this point, so you can see what the signs are if you think your daughter is having some "queen bee" moments. It will really help you see what this behavior can look like later and give you ideas on how to work with her now.
Is this mostly focused around this one particular friend or does she say hurtful things to other kids? Might be worth a talk with her teacher too, to see what goes on at school that might not be worth "reporting" to you but might shed light on whether she does this there as well. Good luck. You are very wise to work with her on these skills and that's going to help her.