Get a second GM
I have been in a game where there was a three-way fight. One team was the players' party. Our GM ran the second team. And our GM brought in her partner (also an experienced GM) to run the third team.
There are a couple of benefits to having another person run the third team. One major benefit is that it reduces the load on you as the GM since you only have to control half as many NPCs. This helps streamline combat somewhat.
Another very important benefit is that this third team will be able to act truly independently. If you run both teams, you will be subconsciously (or consciously) colluding with yourself and the three-way battle won't feel as authentic. The different play-style of your assistant GM will be evident to your players and this extra set of NPCs will feel different to if you had run them. And by having another person running the third team, there will be the added thrill of all three sides genuinely fighting to win.
Have rich goals
This fight will be long and slow, even with a second GM. As such, you need to make the fight narratively rewarding and more engaging than 'I hit them until they die'. Enkryptor was spot-on when he said that every combat should have a goal.
In my particular example, the goal of all three parties was to 'get the girl', a plot-critical NPC who was a long-time member of our party (so we were protecting her while the other parties both tried to take her for themselves). Because we had a goal which was more complicated than simply 'kill everything' the combat was more dynamic and exciting. There was the added complication that no side wanted the girl to die, even though the girl was quite capable of fighting back, so extra care had to be taken. It was a goal that we the players were quite invested in, which motivated us through the battle. And it meant that some NPCs fled when heavily wounded and left their underlings take care of the mission, which made the battle more authentic than people pointlessly fighting to the death.
The objectives of the three factions should also be such that there can be only one winner. If, as in your example, the goal of both the party and the secondary antagonist is to kill the main antagonist, then the most logical arrangement is for the secondary antagonist to temporarily side with the players, reducing the battle to a two-sided one. However, in my scenario, only one team could get the girl, so we all fought tooth and nail to make sure it was ours. There could be no parley, not without losing her.
Allow lots of time
This battle will take an entire session. It will likely be a long session. Plan accordingly. You should end the previous session just as you've set up the battle and combat seems inevitable, even if that means ending early, otherwise you will not have time for your planned battle. This also builds up the hype for your players.
Abstract away unimportant creatures
In such a large battle, you are likely to have mooks fighting mooks. However, your players don't care about the mooks, they care about themselves and the major NPCs.
You can substantially reduce the number of active characters in the encounter while maintaining the scale of the battle by going "this group of soldiers is fighting this other group of soldiers and they are both busy doing that" with an implicit "they won't bother you if you don't bother them". The outcome can either be determined as is narratively convenient or with a few quick dice rolls, although the result should be withheld until either the end of the battle or when it becomes relevant. This puts greater emphasis on the characters which matter while keeping a cinematic feel to your epic battle.
(This advice applies to all battles with many NPCs, not just three-sided ones.)
I recommend getting a second GM to run the extra faction. I recommend that each team have mutually exclusive goals which means that they all must fight against each other, and that these goals should be more elaborate than "I want everyone else to die".
If none of these options work for you, you may need to reconsider doing a true three-way battle.
You might want to run the NPC vs NPC battle beforehand and let the players intervene when they see fit (if it is appropriate for the players to ambush the NPCs).
You might have the players fight just the main antagonist, then when the battle is almost over the secondary antagonist swoops in and ambushes both parties. This makes it a two phase battle. Because one NPC team will be mostly (or entirely) dead by this point, the second phase would run quite similarly to a normal two-sided battle.
Or, if the narrative allows, you might have the secondary antagonist make a temporary truce with the players. Then the battle will be reduced to two factions and end up being simpler to run.