Jay Timmons and Rick Olson, a married gay couple from Virginia, didn’t think they’d have any trouble becoming the legal parents of the baby boy their surrogate, a Wisconsin woman, delivered for them last year.

They had gotten the frozen embryo that became their son as a gift from straight friends whose in vitro fertilization created more embryos than they could use. They had chosen a Wisconsin surrogate specifically because the state's Supreme Court had upheld surrogacy, and other same-sex couples had had smooth sailing there. And by just about any measure, the two intended fathers were prime parent material: They both had good jobs, they had been together for 25 years, and they were already raising two daughters from previous surrogacies.

But their careful plans went awry the month before their son, Jacob, was born, when their effort to be named his legal parents landed before a conservative judge who saw surrogacy as a form of human trafficking. Over the next 11 months, the couple’s bizarre legal battle cost more than $400,000 and kept them in constant terror of losing their son.

“We didn’t have one night’s peace,’’ Timmons, 54, a conservative Christian and president of the National Association of Manufacturers, told BuzzFeed News. “We’d wake up absolutely panicked, around 2 in the morning, and talk about the fact that we didn’t know what was going to happen.”

The couple took out second and third mortgages to cover the legal fees, and Olson, 49, quit his job as a federal lobbyist for Capital One to manage the proceedings.

Over the last couple of years, a handful of high-profile surrogacy lawsuits have cropped up in U.S. courts. In California, a surrogate named Melissa Cook refused a man’s wishes to abort one of the triplets she was carrying for him. And in a Pennsylvania, The View co-host Sherri Shepherd tried, unsuccessfully, to pull out of a contract with a pregnant surrogate after splitting up with her husband.

But the Wisconsin case is likely unprecedented, legal experts say, in that the surrogate, her husband, and the intended parents were all happy with their arrangement. Only the judge was not.

The case was a “judicial hijacking,” Melissa Brisman, a surrogacy lawyer in New Jersey, told BuzzFeed News. “We’re at a time when a lot of people are still very committed to the idea that family values means straight married couples who have sex are the only ones who should have babies.”

In June the couple won the case, thanks in large part to the judge’s abrupt resignation. Although the proceedings had played out in closed court, once it was over, supporters of Timmons and Olson provided copies of court transcripts, briefs, and filings to BuzzFeed News. And although the case is certainly an anomaly among the thousands of surrogacy arrangements made in the US every year, it underscores how, in certain areas of the country, surrogacy has become a flashpoint for cultural debates about same-sex marriage, reproductive rights, and the booming fertility industry.

Judge Jim Troupis opened his March opinion with the statement, “Human trafficking comes in many forms.”

Dane County Circuit Court Judge Jim Troupis, appointed by Gov. Scott Walker last year, opened his March opinion with the statement, “Human trafficking comes in many forms.” And although he went on to describe the two dads as a “spectacular set of parents’’ who would raise the child “in a nurturing environment with unmatched financial resources,’’ he made it clear that he was bothered by the fact that the couple had paid a woman to carry a baby who was not related to them.

“The fundamental fact remains that another couple has provided the child as a gift to the petitioners, and the child has no genetic relationship to the petitioners,’’ Troupis wrote. “In order to bring the child into world, the petitioners have paid a significant amount of money. Without those payments there would be no child.’’

Surrogacy is unquestionably expensive: Even before they ran into trouble and began accruing bills from a dozen different lawyers, the Virginia men paid $35,000 to their surrogate and another $12,500 to the Wisconsin agency that arranged their contract.

Some people see these arrangements as selling babies, or exploiting poor women’s bodies. But others, including many feminists, say women should be able to use their bodies as they please.

There is no federal law on the subject, and state laws vary enormously. California, for example, where Timmons and Olson hired the surrogates who delivered their two daughters, is the center of the nation’s surrogacy industry, thanks to a friendly state law.

But most states don’t have any surrogacy laws on the books. Some simply refuse to enforce surrogacy contracts. Others, including Virginia, don’t allow surrogacy unless at least one of the intended parents has a genetic connection to the baby. New York and Washington allow only unpaid, or “altruistic” surrogacy, and Michigan has criminal penalties for all types.

“We’re not getting any closer to a national consensus on the subject,’’ Naomi Cahn, a family law professor at the George Washington University Law School, told BuzzFeed News. “And it’s not just a split between red states banning it and blue states supporting it.”

Despite the legal limbo, because of the rise of in vitro fertilization — now responsible for nearly 2% of US births — and the legalization of same-sex marriage, demand is also rising for surrogates. And, partly to avoid legal snags, these women are generally “gestational surrogates,” meaning that they carry embryos that are not genetically related to them. According to the CDC, there were 3,432 gestational surrogates in 2013, up from 727 in 1999.

A petri dish containing an embryo at the IVF lab at New York University’s Langone Fertility Center.

Timmons and Olson say they were not thinking much about adding to their family until their friends asked if they wanted their two leftover frozen embryos (only one of which survived). The California surrogacy agency that had helped the two men get their daughters was no longer in business. So they researched the various state laws and chose Wisconsin because it allowed same-sex marriage and had a state Supreme Court ruling upholding surrogacy contracts where they are in the best interests of the child.

The Wisconsin proceedings started smoothly. Their agency, Pink and Blue Surrogacy and Fertility of Waterloo, found them a surrogate. And before Jacob was born, Judge Sarah O’Brien, who was filling in to cover a vacancy on the county court, issued an interim order giving them parental rights, which would become permanent once the baby was born and had a birth certificate.

Jacob was born Aug. 17, 2015, but by that time, the case had been transferred to Judge Troupis, who had recently been appointed to the court. He nixed Judge O’Brien’s order, and appointed an independent lawyer to represent Jacob’s interests in the proceedings.

Although the case was in Dane County, the liberal stronghold that contains Madison, Judge Troupis appointed as the child’s legal guardian Mark Knutson, a lawyer 70 miles away whose radio broadcast, The Word on The Law, aims to reconcile God’s word with the law. Knutson, in turn, brought in another lawyer from his firm, Erik Krueger, who had worked with Liberty Counsel, a group that defends public officials like Kim Davis, the Kentucky county clerk who refused to issue marriage licenses to same-sex couples.

Timmons and Olson were for the most part allowed to keep Jacob at their home in Virginia, although at one point, Timmons had to stay in Wisconsin with Jacob while Olson and the girls returned to Virginia for the start of the school year.

Rather than following the first judge’s lead, and formalizing the couple’s parentage rights on Jacob’s birth certificate, Knutson insisted on full-bore legal proceedings. Instead of conducting informal interviews with Timmons, Olson, the surrogate, her husband, and officials from the surrogacy agency, Knutson required them all to testify at formal depositions. And while many surrogacy cases in Wisconsin do not involve an independent legal guardian, and those that do usually have fees of less than $1,500, Knutson’s bills topped $100,000 — to be paid by Timmons and Olson.

In November, Knutson filed a 45-page report to Judge Troupis, calling for more court oversight of surrogacy cases and arguing that rubber-stamping a gestational surrogacy contract made by two men with no genetic connection to the child would open the way to a dangerous expansion of the concept of parenthood.

Such surrogacy contracts, his report said, broker pregnancy, commodify children, and meet the needs of wealthy intended parents at the expense of the children involved.

And, he warned, they stretch the boundaries of parenthood beyond all recognition, almost to the point of creating a world, like the one in Plato’s Republic, in which all children would be raised communally, with no special connection to their parents. “Plato’s assertion that ‘no child should know its parent’, once anathema to American jurisprudence, is not so different from paying for parental rights in this case,” Knutson wrote.

In his March decision, Judge Troupis seemed to rely on many of Knutson’s arguments. He terminated the surrogate’s maternal rights and gave the Virginia men only temporary custody, technically leaving Jacob an orphan. Knutson declined to comment for BuzzFeed News, and Judge Troupis could not be reached through his law office.

As news of the case spread, LGBT rights advocates were horrified.

“This case is an indication of the work that’s left to be done,’’ said Emily Hecht-McGowan, director of public policy at the Family Equality Council, an advocacy group that supported Timmons and Olson. “There’s a sense in the gay community and among parents at large that now that we have marriage equality, all the issues are resolved, and same-sex couples will be treated like everyone else, but that’s not yet true.’’

The Troupis decision left Timmons and Olson at a crossroads: They could continue to appeal in Wisconsin, or take a different route, pursuing an adoption in their home state of Virginia. While they weighed these options from their home in Virginia — while caring for Jacob and their young daughters — they had a lucky break: Judge Troupis resigned May 2, to try, unsuccessfully, for a seat on the Wisconsin Supreme Court.

Timmons and Olson had already moved to reopen and reconsider Judge Troupis’s ruling, but with the judge’s resignation, their case was transferred to yet another judge, Peter Anderson, who overturned Judge Troupis’s “faulty’’ opinion, which he criticized for using language that was “unduly harsh and kind of weird.’’

Since their victory, Timmons and Olson have spent the summer fighting Knutson’s huge legal bills, and going public with their story to try to prevent similar actions by rogue judges elsewhere.

“Our biggest concern is that you had a judge ignoring the law, ignoring precedent, with intention to take Jacob away, or to torture us, based on his personal opinion,’’ Timmons said. “We’re using our voices to try to make sure this never happens to another family.”

CORRECTION

Aug. 27, 2016, at 17:28 PM

Judge Troupis appointed as the child’s legal guardian Mark Knutson, who in turn brought in another lawyer from his firm, Erik Krueger. An earlier version of this story swapped the two men's first names.