For nearly three months, Roeuth An sat behind the walls of his immigration detention cell, dreaming of the day he might return to his family in Washington state.

But two weeks ago, the 45-year-old electrician and father of two who came to the U.S. as a Cambodian refugee became convinced that day would never come. An learned he was among roughly 46 Cambodians scheduled to be shipped back to their homeland by Dec. 19.

With the clock ticking, An's lawyers scrambled to seek relief for the decades-old crime that qualified him for deportation — a conviction as an accomplice in a 1994 drive-by shooting.

The ICE-chartered flight was just days away when An received his ticket to freedom. It came not through an immigration court appeal, but by way of a less traditional venue: the office of Washington governor Jay Inslee.

An had been pardoned.

Four days later, an immigration judge ruled he could be released while waiting for his pardon to be reviewed in court. An would not be getting on the plane to Cambodia.

"I was more confused than happy," he told NBC News a day after he was released from detention. "My mindset was that I was already being sent back. I didn't think I had time for the lawyers to get me released."

An is among a small but growing group of immigrants, many of them Cambodians in Washington and California, spared from the Trump administration's deportation crackdown by an eleventh-hour pardon.

Most people fight deportation orders where they're issued: immigration court. But advocates for those whose deportations were triggered by long-past criminal convictions, including many Cambodians, are trying a more creative route.

Attorneys for immigrants facing deportation in Washington and California have petitioned governors for pardons, arguing that in the years since these convictions, residents like An have lived productive, crime-free lives. Once an immigrant's criminal record is swept clean, they return to immigration court to try to get the order of deportation removed.

Roeuth An with his wife Somphon Hok Courtesy Somphon Hok

An's chances look good. Gov. Jerry Brown of California has pardoned at least seven Cambodians facing deportation since 2017, enabling them to stay in the country. Gov. Inslee of Washington has now pardoned two. These immigrants are just a tiny fraction of those being deported, but the way they've won their freedom highlights how liberal governors are wielding state powers to push back on Trump administration policies.

Advocates say Cambodians can often present particularly compelling pardon cases. The majority arrived in the U.S. legally as refugees, and qualified for citizenship long ago. Had they known to fill out the paperwork, many would not face deportation today.

"They did rehabilitate themselves, they have reintegrated into the community, they just didn't understand [years ago] they could take the opportunity to become U.S. citizens," said one of An's lawyers, Joanne Kalas. "If they had become citizens, they would have been treated just like any other citizen."

The Trump administration's immigration crackdown has impacted communities across the U.S., and Cambodians, who are clustered in states like Washington and California, have been hit hard. The flight next week will be the third large deportation of Cambodians in 2018, and the latest in the push to increase removals to Cambodia and other countries that have historically resisted accepting U.S. deportees.

At least 110 Cambodians have already been deported in 2018, said an ICE spokesperson. It's the highest number in at least 15 years — as far back as deportation data is publicly available. It's more than triple the number deported in 2017, according to the Transactional Records Access Clearinghouse (TRAC).

A diplomatic note obtained by NBC News shows that the ICE-chartered flight will arrive in Phnom Penh on Dec. 19 escorted by ICE agents. A spokesperson for ICE declined to comment on the flight, saying the agency does not comment on future deportations "due to operational security." The State Department deferred to DHS.

"Prior administrations allowed countries to refuse to repatriate their criminal nationals — this president has made it clear that is not acceptable," said DHS spokesperson Katie Waldman.

Anoop Prasad, a lawyer with the Asian Law Caucus in California who has successfully fought deportation orders for many Cambodians, said the frequency and size of raids on Cambodians has been "devastating."

"It's like they've packed five years of raids into one year," said Prasad. "The level of fear is off the charts."

Many of those being shipped out of the country now were ordered deported years ago. But those deportation orders changed little about their daily lives because, until recently, Cambodia refused to accept most deportees from the U.S.

The push to deport Cambodians began under President Barack Obama, leading to public outcry and grassroots organizing in the Cambodian community in 2016. It has accelerated since the start of the Trump administration, when the president signed an executive order in his first week in office that directed the State Department to increase diplomatic pressure on countries like Cambodia that were resistant to accepting deportees.

Since then, the administration has placed visa sanctions on six countries, including Cambodia, for their lack of cooperation. It is an aggressive but little-noticed piece of Trump's immigration agenda. The administration has redirected hundreds of millions of dollars and shifted diplomatic priorities in its effort to increase removals to countries, most in Africa and Asia, that have previously dragged their feet or refused to accept deportees from the U.S.

"They've been shipping people off steadily," said Charisma Sing, a community organizer in An's hometown of Tacoma, where there is a large Cambodian population. "The community is shrinking. ...Raids used to be once a year for the past five years in Tacoma. Now it's monthly. It's tearing a lot of families apart."

Always checking in

For most of his life, An thought of himself as an American.

He was just seven years old when his family relocated to the U.S. in 1981 after fleeing the genocidal Khmer Rouge regime. They were part of a mass exodus from the violence and destabilization that consumed Southeast Asia after the U.S. pulled out of the Vietnam War. More than 150,000 Cambodians were resettled across the U.S., many in poor communities.

An grew up in a rough section of Tacoma, wracked by crime and violence in the 1990s. One night in 1994, he gave a ride to a friend who was in a gang. As they drove past three members of a different gang on the sidewalk, An's friend yelled at them, then drew a gun and fired, wounding one person before An drove away, according to court records. Both were arrested and An was charged as an accomplice to the shooting. He was 21 years old.

An took a plea deal to avoid trial and receive a lighter sentence. He got 18 months in prison, only learning later the plea came with strings attached.

Not long after arriving, An said, he was visited in prison by immigration officers who told him he was not an American and could now be sent away.

"Mr. An did not fully understand what was happening at the meeting," his pardon application states, "but recalls immigration officials asking him to sign a document regarding his place of birth and learning for the first time that he was not a U.S. citizen. ...Mr. An was later informed he had signed a document agreeing to his removal or deportation from the United States."

Like many Cambodian refugees, An's family hadn't realized they had to apply in order to change their status from legal permanent residents to citizens. They had thought the process was automatic.

"After so many years, I always felt I was one of them," An said. "I didn't know you had to take a test to become an American."

An wasn't booted out of the country because Cambodia refused to accept most U.S. deportees. So he lived his life. He became an electrician, fell in love and raised two kids (both U.S. citizens). He went salmon fishing on the Nisqually River, took his step-daughter and son to pumpkin patches and Christmas tree farms and organized birthday parties for his infant grandchildren, all the while checking in regularly with ICE officials.

His criminal record has been clean since he left prison 20 years ago.

"As time went by, because I was living basically as a U.S. citizen, I'd thought that it would just go away eventually," An said.

By the start of 2018, An's check-ins with immigration authorities had moved from every three to six months to monthly. He and his wife Somphon Hok were getting worried. They met Shelly Bingham, the wife of a Cambodian refugee named Sophy Hem who had been pardoned by the governor in July. She connected them to two pro-bono attorneys, Kalas and Andrea Bradford, who helped An submit a pardon application the following month.

Sophy Hem hugs his wife Shelly Bingham after the Washington state pardon board ruled on June 8 to recommend that governor pardon him. Courtesy of Shelly Bingham

When An got a letter asking him to report for his monthly check-in early, on Sept. 14, he and Hok feared the worst. Hok and his two lawyers came with him.

"When they called him in, we all went into the room and they told him, 'At this time Mr. An, we have to detain you,'" Hok said. "He gave me a hug and told me to keep working and keep going." For the next three months, she only saw him through a glass wall.

An's pardon hearing was scheduled for Dec. 13. But when An's lawyers learned two weeks beforehand that he would be transferred to Texas on Dec. 11 and deported to Cambodia on Dec. 19, they pushed to speed up the process. They requested an emergency pardon from the governor due to An's impending deportation. Four days later, Inslee signed the pardon.

Then it was a race to reopen his case in immigration court. The pardon made the order invalid, but it remains in effect until struck down by an immigration judge. That process takes time, often weeks, but the day before An was set to go to Texas in preparation for deportation, he was released on supervision.

Hok was on her way to the detention center when she learned the news. "I just thought I was going to visit him," she said. "I didn't know at all."

An's deportation order still stands, but he's been allowed to stay in the country while he waits for an immigration judge to decide on his case now that he has a pardon.

After leaving the detention center together earlier this week, An and Hok grabbed a bowl of pho from one of the many Vietnamese noodle soup shops that dot Tacoma. But it wasn't until An returned home that his release began to fully sink in.

"It was actually the smell that really brought me back home," he said. "That familiar smell of home — I really knew I was back."