Massachusetts last year deported the lowest percentage of illegal aliens of any state in the nation — and had the third highest rate of granting asylum, according to a Herald investigation of a largely secret system that shows the Obama administration’s increasingly lax policy on immigration.

The state’s immigration court, nestled in a largely unobserved space on the third floor of the John F. Kennedy Federal Building downtown, deported just 26.9 percent of illegals who came before it, the country’s lowest average rate — and well below the national average of 46.4 percent, records show.

That fits a rapidly accelerating trend that saw Bay State judges ordering the deportation of 80.5 percent of illegal aliens just 10 years ago, a rate that dropped every year but one until hitting an all-time low last year, according to the Transactional Records Access Clearinghouse (TRAC), which crunches government data.

The Massachusetts court also ranked third in the country in the percentage of asylum claims granted last year, at 75 percent, according to a Department of Justice report.

The Massachusetts court also has the dubious distinction of having one the longest average lengths of stay for convicted felons before a decision is made on their deportation cases.

An Immigration and Customs Enforcement (ICE) report issued to a congressional committee in July showed criminals placed in deportation proceedings in the Boston area had an average stay of 92.4 days last year, the third longest in the country behind New York (116.8 days) and Seattle (94.3 days).

The Massachusetts court completed 4,713 cases last year, according to TRAC, the country’s 12th largest caseload.

The Herald probe comes as immigration and border security have become hot-button issues in the race for the White House, with Donald Trump calling for zero tolerance for illegals and a wall along the Mexican border, and Hillary Clinton basically vowing to extend President Obama’s policies.

The Herald investigated the secretive court, how it operates, who’s in charge and how its outcomes compare to other states.

New York, for instance, had the second lowest deportation rate to Massachusetts last year, 27.5 percent. Those rates contrast starkly with states like Texas (62.4 percent deported), Georgia (71.4 percent) and North Carolina (79.1 percent).

Jessica Vaughan, director of policy studies at the Center for Immigration Studies, a conservative group critical of U.S. immigration policy, said low deportation rates reflect Obama administration policy changes that favor immigrants.

These changes include giving greater judicial weight to whether illegals have children in the U.S., and granting more asylum claims on the basis of a generalized fear of violence in their home country, instead of a specific threat.

“Under the law, the burden is on the alien to show that they qualify for relief — that has been flipped on its head,” Vaughan said. “It’s become a system where the illegal alien or applicant for relief is given the benefit of the doubt.”

Kathryn Mattingly, a spokeswoman for the Executive Office for Immigration Review, which oversees immigration courts, said each case “has its own set of facts and variables that affect its outcome.”

“Immigration judges adjudicate matters on a case-by-case basis, according to U.S. immigration law, regulations, and precedent decisions,” Mattingly said in a statement. “Immigration judges consider all evidence and arguments presented by both parties and decide each case based on that information.”

Mattingly said the office monitors case outcomes through an evaluation system and “takes seriously any claims of unjustified and significant anomalies in immigration judge decision-making and takes steps to evaluate disparities in immigration adjudications.”

Unlike many states, Massachusetts has only one immigration court, in Boston. When the Hub court’s deportation rates are compared to other individual city courts, not statewide averages, it ranks around eighth most lenient, with Phoenix topping the list.

Retired former Boston immigration judge Eliza Klein, who also served in the Chicago and Miami courts, said the low removal rate in Massachusetts is likely tied to how much more often aliens seem to secure lawyers here than in other states.

“I think people get fair hearings there, and I think when you see fair hearings, you get more relief granted,” Klein said of the Boston court, adding that, unlike courts on the border, Boston sees cases where it’s often less clear-cut how and when illegal immigrants entered the country, and what relief they might be eligible for.

“There are immigration courts where attorneys who are representing respondents are perceived as part of the problem, a hurdle that a judge has to get through in order to complete their job,” Klein said. “And my view is that any time there’s an attorney in a case, it made my job easier.”

Illegal aliens do not have a right to a court-appointed attorney, but have due process rights. Family members often pay for their lawyers, and some legal aid groups offer pro-bono services.

The Herald noted several instances in which a judge in the Boston court seemed hesitant to resolve a case when undocumented immigrants did not have legal counsel.

In one case, a man from El Salvador told Judge Steven F. Day he feared torture if he returned home, but didn’t have money for a lawyer. Day passed him a list of attorneys. The man said he’d seen the list, but “they don’t answer the phone.”

“Well, you have to be persistent,” Day replied.

In another case, Day denied bond to a Guatemalan who had been picked up on drunken driving charges in Massachusetts and did not have a lawyer. He said he was seeking asylum because he’d been extorted and threatened in his native country by people whose names he did not know.

But he was eager to get back to supporting his family, and asked, “This might sound like committing suicide, but what if I want to be deported?” After some back-and-forth, Day convinced the man to delay his decision for a week, and entered an appeal of his own bond denial on the man’s behalf.

Matt Cameron, an East Boston attorney who regularly represents immigrants before the Boston court, said the area has seen a recent surge of Central Americans who legitimately fear for their safety and qualify for asylum.

“We have refugees fleeing hollowed-out countries overrun by gangs, catastrophic in the last couple of years,” Cameron said.

Experts say declining deportations are also fueled by a change in ICE priorities. A 2014 Homeland Security directive told the agency to target apprehensions of aliens who are national security threats, been convicted of a violent offense or have an aggravated felony or three misdemeanor convictions on their records.

This priority list, Vaughan said, has opened up more doors for lawyers to make a case their clients should be allowed to stay.

The July ICE report showed the agency had completed 168,781 departures this fiscal year, well on track to be the fourth straight year of declines since 2012, when there were 409,849.