For weeks, “Grey’s Anatomy” has been teasing Callie and Arizona’s emotional custody battle. And just as promised, the Season 12 installment was full of heart-wrenching moments.

Episode 22, titled “Mama Tried,” began with Meredith (Ellen Pompeo) comparing Callie (Sara Ramirez) and Arizona’s (Jessica Capshaw) situation to the Judgment of Solomon — a Bible story that involves two mothers claiming the same child. The wise king decides to split the baby in half — literally — which is when the child’s true mother gives up custody so that the baby can survive.

“But what happens when there are two true mothers?” Meredith asks in the hit ABC installment. “Well, that is an entirely different story.”

Neither of Sofia’s (Eva Ariel Binder) mothers wanted to back down, which is why they brought their case to court hoping that a judge could pick a sole guardian of their daughter. Initially Arizona’s attorney tells her that going to trial could result in her losing Sofia. After all, Callie has two star witnesses speaking on her behalf while Arizona just has Weber (James Pickens Jr.). But Arizona stays positive and marches into court the next day for the first hearing.

Meanwhile, Arizona’s former patient Jenny (Morgan Lily) gets readmitted to Grey Sloan Memorial Hospital after falling on dishes. The lacerations on her stomach require the pregnant teenager to endure a procedure, conducted by Alex (Justin Chambers), allowing him to see the internal damages.

As Alex begins surgery, with Arizona’s blessing, audiences watch as Owen (Kevin McKidd) is the first witness called to the stand. He gracefully states how dedicated a mother Callie is and how she’s able to “make the best of a tough situation.” DeLuca (Giacomo Gianniotti) is called next, and he too is able to paint a pretty picture on the behalf of his roommate Arizona.

But things get interesting when Penny (Samantha Sloyan) is questioned. Arizona’s lawyer rapidly fires question at Callie’s girlfriend after Penny claims to know Sofia “very well.” And although Penny is able to correctly state Sofia’s favorite color, animal and cereal, she’s unable to remember what clothes Callie and Arizona’s daughter was wearing that day or what grade Sofia’s in. And for a woman about to become a parent to Sofia, that doesn’t exactly make her sound like mother material.

“Maybe it wasn’t that bad,” Callie says after the first hearing concludes, only to have her lawyer respond that they’re in a terrible spot. So the attorney breaks out the big guns for day two as Bailey (Chandra Wilson) compared the hectic schedules of Sofia’s parents.

Although both of the surgeons have unpredictable schedules, it was recorded that Arizona took part in 92 unscheduled surgeries while Callie was called for about 20. “So, 92 times [Arizona] chose work over her child,” Callie’s lawyer sums up her point. But Bailey fires back that during those 92 surgeries Arizona chose to save babies.

But Callie’s lawyer isn’t the only one with a clever plan up her sleeve. When Meredith takes the stand, Arizona’s lawyer is able to draw out crucial information bolstering her case that begins with a simple question: Who’s watching Sofia now? Meredith explains that her sister Amelia (Caterina Scoresone) is currently watching their child, adding that due to being single parents they lean on each other. Meredith adds that it’s not a sign of weakness to ask for help.

“It takes a village and we have a village,” Meredith says, proving the point of Arizona’s lawyer. According to the attorney, if Callie was to take Sofia to New York, she’d be leaving her village in Seattle. She’d be leaving her friends, family, the people who love and take care of her.

While Calzona fight over custody of their child, Alex fights to keep Jenny’s baby alive. After the procedure they learn that amniotic fluid is in Jenny’s abdomen, which is when Arizona’s replacement declares that he needs to deliver the premature baby. But Alex and April (Sarah Drew) think that’s a rash decision. So, they page Arizona with the emergency — a call she gets in the middle of her testimony.

While Arizona is on the stand, Callie’s lawyer attempts to imply that Arizona is somehow less of a mother to Sofia because they don’t share the DNA. But Arizona fires back that it was her choice to adopt Sofia.

“There was a choice, and I could stay or I could run, and I chose motherhood and it was the best choice I ever made,” she says before needing to make another decision — to leave the courtroom.

“Somewhere more important to be?” Callie’s lawyer asks.

“Actually, yes,” Arizona replies. She explains that no matter who the judge gives sole custody to she knows her daughter will be safe, healthy and loved. “But there’s a child at the hospital who will not survive if I’m not there. So I have to go.”

Arizona races back to Grey Sloan Memorial moments before Jenny’s baby is delivered via C-section. She figures out a way to safely put the premature baby back inside of the mother, giving the child a better chance at survival.

The next day, viewers see the surgeons of Grey Sloan staring at their phones, waiting for either Callie or Arizona to reveal which one of them was given sole custody of their daughter. But instead of finding out through a measly text, audiences learn who the judge picked when the camera cuts to Callie sobbing uncontrollably.

“How the hell did this happen?” she asks. “How the hell did this happen?”

Meredith comforts her as Penny attempts to console her girlfriend through an empathetic hand rub. But Callie flinches, throwing Penny’s hand away in disgust. Looks like Penny just became Callie’s scapegoat — after all, it was Penny who encouraged her to move to New York, wasn’t it?

Were you surprise that Arizona was given custody of Sofia? Sound off in the comments section below. “Grey’s Anatomy” airs Thursdays at 8 p.m. EDT on ABC.