MAJOR SPOILERS BELOW.

I'm in the last fight and have figured it out to the point where I get the elder brain down to below 50hp. Basically one turn away from death. But before I get a chance to act, all sorts of quick cutscenes occur, a nautiloid shows up, and I get the "Your party has died. Load new game." message. HUH?

Steps I took to get there:
- Summon all my allies.
- Focus attacks on the Emperor. Kill him.
- Haste/Misty Step/Fly to get everyone to the portal.
- Use stones on portal. OPen it up. Move party inside while summoned allies deal with Mind Flayers and dragon.
- Move to brain, attack.
- First round of attacks gets it to about 50hp.
- Party wipe.

I'm missing something obvious but after three attempts, I'm not seeing it. Any advice?