how could someone with a knife and a shield fight someone with a sword and not die, if running away wasn't an option?
Bash them with the shield.
It’s easy to look at shields as a strictly defensive item, but they are a weapon. Historically shields saw some pretty aggressive use in combat. Shields aren’t simply about blocking an enemy attack, they’re also for retaliating, and creating openings in your opponent’s guard. This may be as simple as (briefly) tying up your opponents weapon by swinging the shield away, after you’ve deflected a blow, or it may be something more involved, such as using the edge of the shield to wedge into an opponents armor, pinning them.
Shields do offer a lot of options to a creative fighter. Including allowing them to close distances, through an enemy’s guard, in ways that an unshielded combatant can’t.
One very simple (and risky) solution to your problem would be to rush the swordsman with the shield up, to prevent them from getting a good swing in, pin them against a wall, and run the dagger through their foe’s neck. It’s risky, because if they’re not able to pin the sword before closing the gap, they could end up running themselves through.
Remember, swords do have a minimum effective range. Get close enough to someone, and they won’t be able to get a good hit in with their sword. While this is also true of shields, it’s not the case with most daggers.
It’s not an optimal situation for dealing with a sword, but a shield does offer options to negate the sword’s advantage over a dagger. The shielded combatant has options for dealing with the sword’s reach. Without that, the knife fighter would be screwed.