Leia used the force, brought out by her survival instinct.
Survival in space is something that seems within the grasp of Jedi to do, as is evidenced by Plo Koon in The Clone Wars
I can withstand the pressure for some time
While it's unclear whether or not this is a skill specific to the Jedi, it seems to be with their grasp. Although Leia is not a Jedi, she is evidently force-capable and may have been able to use the force to keep herself alive.
Rian Johnson confirms that this is something to do with the force, related to a survival instinct, like Luke in ESB
I liked the idea that it’s not Luke concentrating, reaching for the lightsaber; it’s an instinctual survival thing, like when you hear stories of a parent whose toddler is caught under a car and they get superhuman strength, or a drowning person clawing their way to the surface. It’s basically just her not being done with the fight yet.
I wanted it to happen [for Carrie] and I knew it was going to be a stretch. It’s a big moment, and I’m sure it will land different ways for different people, but for me it felt like a really emotionally satisfying thing to see.
Inverse - ‘Last Jedi’ Director Explains All the New Force Powers (and the Leia Scene)
This is re-confirmed in an interview with IGN:
“This is a reflex action on her part,” Last Jedi writer-director Rian Johnson explained. “It’s the equivalent in my head of when you hear about parents, toddlers are caught under cars, and they suddenly get Hulk strength and can lift it up. Or a drowning person climbing their way to the surface." ...
“It’s instinctual, her use of it. It’s the opposite of when Luke Force-pulls the saber in Hoth. It isn’t like, ‘I’m going to try and do this.’ For her it’s just an instinctual thing of, ‘I’m not done yet. I’m not giving up. I’m pulling myself back in.’”
Star Wars: The Last Jedi Director explains Leia's relationship to the Force.
Creatures such as the Purrgil were able to survive the vacuum of space even though they weren't Force-Sensitive, how they could isn't clear, but they were also able to jump into hyperspace.
Out-of-universe
After Carrie Fisher's untimely death, Kathleen Kennedy and Rian Johnson had discussed changing the scene to make it so that Leia died "drowned in moonlight" as she had so famously wished for, however they had decided not to change the scenes and to leave the survival intact.
“We were a little ways into postproduction when she passed away, and so we had it mostly put together,” Johnson said. “We didn’t really end up changing it. And that includes adding lines back in that we had cut out or anything like that.”
Vanity Fair - Star Wars: The Last Jedi—What Happened to Leia?
The decision to not make the death so in-line with Fisher's iconic quote may have changed the beauty of the scene out-of-universe, but Fisher still had a role to play In-Universe. It also makes it clear that as beautiful as the parallel is, it’s not certain that this was the intention of the scene, as it had been filmed before her death.