WARNING: The following contains major spoilers for Lucifer's Season 5B, streaming now on Netflix.

Lucifer's longtime frenemy, Det. Daniel Espinoza, is the center of the wildly funny twelfth episode of Season 5, part of the show's newly released second half. Like any good supporting character spotlight episode, "Daniel Espinoza: Naked and Afraid" sends Dan on a journey full of escalating drama and mishaps, leaving him with a fresh outlook on life, but this time there's a twist that ties back to an incident earlier in the season.

At the end of Episode 7, "Our Mojo," Dan finds out that Lucifer really is the Devil he claims to be. Panicked by the implications, Dan storms Lucifer's penthouse and shoots him in the chest. This leads to a number of important plot points, including Lucifer's discovery that he's no longer vulnerable around Chloe, but Lucifer's disproportionate personal pride causes him to treat the attack as if he were simply on the receiving end of a prank.

RELATED: Lucifer's Musical Episode Soundtrack Is Available to Stream and Download

When his preoccupation with the perceived insult distracts him from the case that he and Chloe are working on, he goes off on his own to plan the perfect revenge on Dan and apparently succeeds. Although before he has a chance to reveal his idea to anyone, Chloe goes missing. With his girlfriend's life at stake, Lucifer puts aside his feud with Dan and they work together to find her, which results in Dan accepting that the Devil isn't actually all evil.

With everything going on for the next few episodes, the effect that the celestial revelation had on Dan doesn't seem to be addressed until the beginning of "Daniel Espinoza: Naked and Afraid," when Lucifer attempts to restore their old dynamic with some ribbing. Dan is uneasy about his friend's real identity, and his aversion hurts Lucifer's feelings. Wanting some time away from the precinct, Dan accepts a task transporting a prisoner from Mexico.

lucifer

Once he arrives, he's delayed overnight, agrees to do a not-entirely-legal favor to help an old acquaintance and then wakes up -- naked and afraid -- next to a bloodied, dead body. Chaos ramps up as Dan attempts to do the right thing and conceal his own mistakes, eventually going to Lucifer for help but still needing to bring in more and more of his friends. Facing police corruption, gang wars and blackmail, Dan finds himself the only survivor of a shootout at Lucifer's club, failing to grab the antidote to a poison that he thinks was injected into his neck.

RELATED: Lucifer Reveals One Major Thing He Learned From His Father

So much happens involving so many people, and Dan can barely believe it was a trick even after Lucifer returns and all of the "dead bodies" get up and applaud each others' acting. However, he's reminded that he does know one person with the resources and imagination to pull it off when Lucifer explains, "Countless hours of meticulous planning, dozens of favors called in... Five million, four thousand, one hundred and fifty-seven dollars spent. Totally worth it."

Dan's equilibrium, as well as his friendship with Lucifer, is restored by the end of the episode. "It's crazy, but I think I needed this," he says. "I've been in a really weird place for a long time. And I think I'm through it now." By that point, even the audience may believe this was the intent all along, but Lucifer has one more reminder about what kind of friend he is.

He explains in clear terms that he wasn't at all trying to help Dan. He was plotting the perfect revenge, just like he said he would. Regardless of intentions, the experience did Dan some good, and given the end of the season, the episode did some good for fans of Lucifer.

Lucifer stars Tom Ellis as Lucifer Morningstar, Lauren German as Det. Chloe Decker, D.B. Woodside as Amenadiel, Rachael Harris as Dr. Linda Martin, Kevin Alejandro as Det. Dan Espinoza, Lesley-Ann Brandt as Mazikeen Smith and Aimee Garcia as Ella Lopez. Season 5B is now on Netflix.

KEEP READING: Lucifer Showrunner Joe Henderson Dissects Season 5B's Chaos