I duked it out with the whole crew and beat them on the second try. (In my first try I just walked right into the courtyard without knowing what was going on due to a bug in my game where Gareth doesn't appear at the rally point, and I got no info about the attack. Alexander completely pantsed my characters with the blinding attack and it was a debacle from there).
Even my successful second try was somewhat suboptimal and I needed several resurrection scrolls I had stockpiled during the rest of the game without previously using them. But I won without any hacks or cheese. I had a level 7 party but I'm not sure how important that is since it seems like the game scales opponents to your level. The worm's initial entrance completely surprised me and killed one of my characters but I was able to regroup and still win eventually.
There are smart comments on here about trying to let the worm and Magisters beat each other up and as much as possible, you just come in at the end to mop up whoever is left. I was able to do a little of that but didn't think of the smoke/blessed smoke/invisibility tactics that some people talk about. When the worm initially surfaced, he was near the Gheist and those two duked it out for a few rounds and left me alone with the other Magisters before the worm randomly moved. That was helpful.
I initially attacked from the right side of the castle (as viewed from Gareth's rallying point), and walked up a staircase to try to get height advantages for my shooter and spellcaster characters. I was also hoping I'd be far enough away to avoid Alexander's radiance/blinding attack but he still got some of my characters with it.
It was an anxious initial few rounds because Alexander, the fighter and rogue were immediately up in my business on the catwalk I'd climbed onto. They quickly depleted my magic armor and some physical armor, but fortunately most characters were still able to fight back. My Red Prince was a tank with an excellent 2-handed weapon doing about 90-120 base damage, and it also granted the overpower skill in just 1 memory slot instead of the conventional 3 that are required if you memorize the spellbook. He was also wearing the Helm of Braccus and I had used it before the battle to get 2 source points enabling me to use Overpower. That, Crippling Blow, and Battle Stomp were very helpful doing a lot of damage and knocking them down.
I developed Lohse as a Hydrosophist/Aerotheurge combo, and she kicked ass in this battle rotating through combos of Hail Strike, Winter Blast, Electric Discharge, Shocking Touch, plus periodically healing people. I accidentally froze the Red Prince for a round or two (we were fighting in very close quarters), when a Hail Strike wasn't far enough away from him, but still worthwhile overall preventing the Magisters from hitting back.
Sebille was a Huntsman and did lots of arrow damage plus did some healing with First Aid. She had a number of knockdown arrows and I think I used some in the initial rounds to control the Magisters.
Ifan was a Rogue/Huntsman/Pyrokinetic, and also stocked with lots of grenades. In this battle I don't recall him using spells, he did melee damage with arrows. I would have liked to use his grenades but the Magisters were too close to Ifan and other characters, if I used them at all it was only later chucking an Armor Piercing one into the courtyard to maul the worm.
At the beginning, Lohse and Red Prince achieved CC of Alexander, the Magister Rogue, and Magister fighter, while the Gheist approached from the courtyard. It was going well until the Worm surfaced. He immediately killed Lohse and diseased + damaged Sebille, but fortunately ended up in the courtyard where he and Gheist fought each other for a while and stayed away from me. I thought about trying to position myself to get the Magisters and worm to fight each other, but decided to just press the advantage I had over the Magisters and finish them off, then gang up on the worm. It pretty much worked out as planned, I indeed killed off the Magisters but after a few rounds the worm disengaged from the Gheist and attacked me. Then the Gheist ran at me, and I ganged up on it + got a quick kill while the worm fortuitously ran off to the courtyard by itself for a while. I then got a round or two of missile attacks in on the worm before it charged up to the catwalk to hit back. It killed Ifan and I had to resurrect him, but meanwhile the Red Prince had several rounds doing huge damage to it (300-400 per round, got some critical strikes and used Crippling Blow on it). From there we just went toe to toe and I had more firepower.