When it comes to dealing with numerous NPC's I don't really focus on individual lines of dialog. Only the important stuff. There needs to be room for the players to interact and interject, though.
So to give an example, during an informal court trial with a lot of people talking all at once.... "Five minutes pass with everyone getting worked up into an angry frenzy. Accusations are being tossed back and forth. You guys notice John the Miller lunge forward before being pulled back by Gabe. John is so angry that when he screams at the prosecutor spittle flies out of his mouth. He is screaming, 'You lying whoreson! You can't get away with this! YOU WON'T GET AWAY WITH THIS! YOU WILL PAY FOR THIS!' John is being physically dragged from the room as his threats continue."
In the above, I got what I wanted across to the players, John's anger and threats. What everyone else was saying is meaningless. If the players are familiar with those involved, they might ask questions like, "What is Mrs. Glassburg doing as John is screaming at the prosecutor?" And then I'd answer that question.
Once players have had a moment to respond or ask questions, I move on with what happens next.
The spotlight should only focus on one or two NPC's at a time, to avoid confusion. You should make clear who is speaking, either by using their name or something fairly descriptive. For example, "The guy in the blue tunic stands up and draws his sword."
The key in these situations is not to get bogged down by the details, determine the point of the scene, and give the players time to ask questions and interject. In the above example, the purpose behind the scene is to give John the Miller a motive in the murder of the prosecutor who will turn up dead later on. What everyone else was shouting during that time was unimportant, though I'd likely also have the PC's roll checks to notice certain other odd behavior from other individuals - perhaps one of whom is the real killer.
It's just the method I've found that personally works best for me when dealing with a lot of NPC's all at once.
EDIT TO ADD: The biggest thing you have to watch out for is creating a situation in which players are merely observing what goes on. They should at least be asking questions about what is taking place, which shows you where their character's attention is directed. You don't want a situation in which you're basically telling players, "Sit and listen to my awesome story!" They need to be able to at least attempt to interact with what is going on, and in situations like this it is helpful to be adaptive and have the ability to change things on the fly. Players can do almost anything to derail you from what you've intended, but the best way to handle that is just to go with the flow. You could easily end up intending to have the players conduct a murder investigation, but instead end up being the prime suspects in such an investigation who are now working to clear their names.