Warning: Major spoilers for Game of Thrones ahead!
When it comes to doing the impossible on Game of Thrones, Melisandre tends to be right at the centre of it all. After all, she's the one who resurrected Jon Snow after he was murdered by his own fellow Night's Watchmen. During Sunday night's Battle of Winterfell, Melisandre arrives again just at the right moment, when they need fire to light the trenches and Daenerys and her dragon are nowhere to be found, and then later pushing Arya in the right direction to finish off the battle in the perfect way. Her arrival is, frankly, something we should have seen coming — because, yes, Melisandre is the closest thing Game of Thrones has to a witch and for that has played a pivotal role in the series.
Technically, Melisandre is a priestess of the god R'hllor, but more importantly, she's capable of prophetic visions and is a "shadowbinder," a magic user from the far-off city of Asshai. She's capable of performing feats of dark magic, typically involving bending shadows (both normal and magical) to do her will. Her magic has been seen at several crucial points of the show, notably when she "births" a shadow that assassinates Renly Baratheon and when she uses Gendry's blood in a dark ritual to curse all of Stannis Baratheon's enemies and rival claimants to the throne. Her magic is often seen in violent contexts, such as when she convinces Stannis to sacrifice his daughter Shireen.
Melisandre's magic isn't all bad, though. After undergoing a bit of a moral shift when she resurrects Jon, she has supported both his cause and Daenerys's, claiming that both of them fulfil the "prince that was promised" prophecy. At the Battle of Winterfell, she arrives and uses her magic to create fire on the swords of the Dothraki and around Winterfell's perimeter to help stop the Night King's army. She later reminds Arya that she's meant to have "eyes sealed shut forever," including blue eyes, which catapults Arya into realising she is meant to kill the Night King.
When it's all over, we're reminded of something we learned back in season six: Melisandre may look like a glamorous, relatively young woman, but when she removes her magical necklace, her true self is actually a wizened old woman. In the episode's final moments, she sheds her necklace, walking away from Winterfell and towards the rising sun, where she collapses and disintegrates into dust, having said earlier in the episode that she would die before sunrise.
Throughout her story, Melisandre's magic has always been a little mysterious and a little bit spiritual, rather than just straightforward, technical spell-casting. Her magic was powerful, but always in the service of what she believed to be right and what she believed the future was supposed to hold.