The investigation and arrest of an Iraqi refugee in Rochester, Minn., last year provide a rare window into how federal investigators use Facebook and other social media tools to identify targets and establish connections.

The FBI had been investigating the refugee, Farass Ali, 34, since early last year for allegedly making a false statement to its investigators. But the agency never arrested Ali or charged him with any crime.

As part of its investigation, the FBI began surveilling Ali's Facebook account last spring. Within a few days investigators found a photo of ISIS fighters on his Facebook page. That same day — May 10, 2017 — agents from U.S. Immigration and Customs Enforcement (ICE) arrested him.

Ali, who came to the United States as a refugee in January 2014 and whose application for legal permanent residency was approved in July 2015, is now facing deportation to the country he fled more than four years ago.

An unsealed federal search warrant affidavit obtained by MPR News details how the FBI gained access to Ali's cell phone, his account on the messaging app Viber and his Facebook profile.

The warrant said Ali was taken into immigration custody by ICE because of inconsistent information he reported on his refugee application.

Yet it's unclear why the FBI began investigating Ali in the first place.

Ali's previous lawyer, John Stevens Connolly, said he handed the case to a lawyer at The Advocates for Human Rights after he fell and broke his left arm and shoulder. Phone calls and an email to The Advocates for Human Rights lawyer were not returned as of publication time.

The FBI said it won't comment on Ali's case.

Law enforcement agencies, such as the FBI and ICE, can access users' private electronic information under the Stored Communications Act, which compels companies like Facebook to disclose information pertinent to current cases.

In recent years, the FBI has sent a slew of subpoenas to Facebook, Instagram and Twitter, asking the social media networks to turn over the personal data of several Minnesota Muslims the agency suspected of being radicalized, even if they were not believed to have committed crimes.

Facebook has recently been embroiled in scandal over allegations that the British political consulting firm, Cambridge Analytica, improperly gained access to the private information of 50 million Facebook users.

The FBI's scrutiny of Ali intensified in the spring of 2017 when Viber Media Snarl, which owns the Viber messaging app, gave agents records associated with a phone number that Ali listed on his refugee application, according to the warrant.

The records showed that between Dec. 1, 2016, and Jan. 30, 2017, the phone number associated with Ali had nearly 40 contacts with a phone number listed on the refugee application of another man, Ali Sabeh Abed, who was seeking refugee status.

The warrant said Abed was listed in a Defense Department report published more than 12 years earlier that identified him as a member of an insurgent cell called Ansar al-Sunna. The cell was believed responsible for attacks on Iraqi and U.S.-led international coalition forces targeting insurgents in Iraq.

The warrant doesn't clarify Abed and Ali's relationship, or even whether that relationship triggered the FBI investigation into Ali.

The FBI agents kept digging into Ali's use of social media.

On May 5, 2017, a month after agents reviewed the Viber records, FBI agents obtained a "pen register" order, which compelled Facebook to provide incoming and outgoing calls on Ali's account.

Five days later, the investigators met Ali at his residence in Rochester. They asked whether he used Facebook and Viber. Ali responded that he used neither of those services, according to the warrant.

The agents asked if they could search his cell phone. Ali declined.

On May 10, agents reviewed photos that were publicly available on Ali's Facebook profile. They found photos of Ali in Turkey, including an image of Ali at what appears to be a gun store that sells hunting rifles. They also found the image of a caravan of ISIS fighters driving in a procession through the Libyan city of Sirte.

Data obtained from Facebook through the "pen register" order revealed that on May 9, 2017, Ali had used his Facebook account to communicate with another Facebook user. On May 11, someone tried to contact Ali through Facebook. Ali did not answer. Another Facebook user tried to contact Ali between May 12-17 and May 20-21.

Ali was unable to answer those calls because he had been arrested by ICE on May 10, days after the FBI started surveilling his Facebook account.

In July, FBI agents obtained a search warrant for Ali's cell phone, which was being held with his personal property at the Department of Homeland Security's local office at Bishop Henry Whipple Federal Building near Fort Snelling.

U.S. Magistrate Judge Steven Rau approved the search warrant.

Records obtained under the search warrant showed that Ali had texted the same image of himself at the gun store to an unidentified person in April 2014, just three months after Ali arrived in the United States.

A message in Arabic read, "See the weapons."

In August, while Ali was sitting in an immigration detention facility, FBI agents obtained a search warrant that would allow them to read his private messages on Facebook.

Meanwhile, Ali had filed a petition challenging the lawfulness of his solitary confinement at the Sherburne County Jail.

"I'm being held in ICE isolation by ICE for about 22 hours a day," he wrote in the petition, which was mailed from the jail on Dec. 19, 2017. "They let me out twice a day, one hour at a time. ICE claims I am unable or willing to be placed in general population. I want to be placed in general population."

A segregation review done by the jail found that Ali doesn't pose a threat to himself or others. Still, his segregation has been classified as "maximum," or high risk.

"This is in violation of the 8th Amendment to the US Constitution, which prohibits cruel and unusual punishment," Ali wrote in the petition.

On Wednesday, a judge dismissed his petition.