Warning: Major spoilers follow for Game of Thrones.
While the Battle of Winterfell raged on during Sunday night's Game of Thrones, another quieter battle was going on deep within the walls. Defended by Theon Greyjoy, Bran Stark, in his Three-Eyed Raven persona, waits as bait for the Night King. Although Bran doesn't do any of the physical fighting against the Night King and his army of the dead, his presence is crucial to the battle and to its ultimate plan to end the Night King's reign of terror once and for all.
While Theon and his men do their best to keep him safe in the godswood in the center of Winterfell, Bran wargs into — what else — a raven, who then flies over the raging battle to survey what's going on. At first, this doesn't seem like a great idea; after all, the show has already established that the Night King can sense Bran's presence, even in warged form, so if Bran is meant to be hiding, it's probably not the best to draw the attention of the seemingly unbeatable ice zombie.
Sure enough, the Night King fights his way through Winterfell, and he and his army arrive at the godswood, where Theon has kept true to his word and taken out every single attacker to protect Bran. Bran returns to himself in time to thank Theon, who then promptly dies in a last-ditch suicide run at the Night King. For a moment, it looks like all is lost, but that's when we realize that Bran luring the Night King has been part of the plan all along.
Distracted by finally finding his target, the Night King isn't prepared when Arya leaps onto his back with a dagger that might look familiar. Although the Night King almost manages to gain the upper hand, Arya's assassin training is no match for him: she switches her weapon to her other hand and kills him, killing all the other wights in the same instant. So, all along, Bran's warging and waiting was simply the bait to get the Night King vulnerable in exactly the right way. Stark sibling teamwork for the win!