Ismail B. Ajjawi, a Palestinian student from Lebanon, arrived at Boston Logan International Airport on Friday, just days away from starting his first year at Harvard University.

But the 17-year-old said he was turned away and sent back to his home country after immigration officials searched his laptop and phone and found social media postings from his friends that were critical of the United States and President Trump.

This is the first known case of a foreign college student being barred from the country potentially based on political views -- views that were not even his own -- expressed online. The move rankled civil liberties advocates, many of whom worry that such actions will dissuade foreign students and researchers from studying in the United States.

The Trump administration has already come under fire for its numerous attempts to bar immigrants from certain countries from the United States and for its widespread denials of visas. Opponents of such policies have said they are rooted in racism and anti-Muslim and anti-immigrant sentiments designed to appeal to the president's political supporters.

Matt Segal, legal director of the American Civil Liberties Union of Massachusetts, said in a statement that if Ajjawi's account is accurate, then it would “confirm our worst fears about current immigration policy and border searches.”

“That they will be used not to improve America’s security,” Segal said, “but instead to impose Trump’s ideology.”

Higher education groups have already criticized a new U.S. State Department policy, which took effect last month, that requires visa applicants to submit information about their social media accounts from the last five years, saying it would deter international scholars from coming to the country.

The barring of the Harvard student, however, was a decision made by U.S. Customs and Border Protection, which has separate rules and regulations from the State Department.

Ajjawi touched down in Boston last Friday night and said immigration officers detained him for hours, questioned him about his religious practices and then searched his phone and laptop activity for several more hours. Ajjawi shared his allegations in a written statement provided to the student newspaper The Harvard Crimson. News organizations, including Inside Higher Ed, have been unsuccessful in contacting Ajjawi.

Ajjawi had arrived at the airport with other international students who were also questioned but were subsequently allowed to leave, Ajjawi said in his statement. He said an immigration officer asked him to remain behind and demanded he unlock his phone and laptop, which the officer searched for about five hours. He said he was detained for a total of eight hours before being told he would not be permitted to stay.

After the officer came back, she took Ajjawi into a room, where she screamed at him and interrogated him about his friends’ social media posts blasting U.S. politics, he said.

Ajjawi’s statement does not contain specific details about the posts other than that they were political in nature.

“I responded that I have no business with such posts and that I didn't like, share or comment on them and told her that I shouldn't be held responsible for what others post,” Ajjawi said in his statement. “I have no single post on my timeline discussing politics.”

The officer then canceled his visa and Ajjawi was allowed to call his parents before being put on a plane to Lebanon.

Customs and Border Control deemed Ajjawi “inadmissible to the United States based on information discovered during the CBP inspection,” Michael S. McCarthy, an agency spokesman, said in a written statement.

“CBP is responsible for ensuring the safety and admissibility of the goods and people entering the United States,” McCarthy wrote. “Applicants must demonstrate they are admissible into the U.S. by overcoming all grounds of inadmissibility including health-related grounds, criminality, security reasons, public charge, labor certification, illegal entrants and immigration violations, documentation requirements, and miscellaneous grounds.”

A State Department official declined to discuss the case, citing federal confidentiality laws.

Ajjawi, who would be due to graduate from Harvard in 2023, was on a Hope Fund Scholarship, which provides financial support for Palestinian youth from the Gaza Strip, the West Bank or Jerusalem to study in the United States. It is administered by America-Mideast Educational and Training Services Inc., or Amideast, a nonprofit that works to improve relations between Americans and citizens of the Middle East and North Africa.

The Crimson reported that Ajjawi had sought legal help through the organization. An Amideast spokeswoman did not respond to repeated requests for comment.

Jason Newton, a Harvard spokesman, said, “The university is working closely with the student’s family and appropriate authorities to resolve this matter so that he can join his classmates in the coming days.”

Classes begin at Harvard Sept. 3.

Harvard’s president, Lawrence Bacow, wrote to Secretary of State Mike Pompeo and Kevin McAleenan, the acting secretary of Homeland Security, last month saying that he had “deep concern” over the administration's immigration policies.

Delaying visas has made international scholars’ “attendance and engagement in the university unpredictable and anxiety-ridden,” Bacow wrote. Students reported they could not get initial visas and they had trouble securing “routine immigration processes” such as visas for family members or clearance for international travel.

Bacow wrote that recipients of the Deferred Action for Childhood Arrivals program were perhaps most vulnerable. DACA temporarily protects from deportation young undocumented immigrants -- many of them students known as Dreamers -- who were brought to the United States as children and allows them to live and work in the country legally.

Students and scholars with Temporary Protected Status -- temporary legal resident status allowed for people fleeing war, personal violence or natural disasters in their home countries -- are also “at risk” under Trump administration policies, Bacow wrote. The White House has tried to eliminate this protection for more than 250,000 immigrants from El Salvador, Haiti, Nicaragua and Sudan, but a federal judge in October issued an injunction blocking the order to revoke TPS.

“The success of the American academic system, particularly at research universities, is based on a vibrant, free and open community that develops talent, produces leaders and creates new knowledge,” Bacow wrote. “Together these university outputs drive innovation that has shaped the economy, fostered new industries and improved health and well-being both in the United States and around the world. I recognize and support the fundamental role of your agencies in ensuring that those who come to the United States do so with appropriate and honest intentions that meet the goals and requirements of our laws. However, the increasing uncertainty around the systems in place to accomplish this task are driving anxiety and fear on our campuses and undermining the impact of our critical work.”

Six major higher education groups, among them the American Council on Education and the Association of American Universities, wrote to the State Department two years ago opposing the rule on submitting social media information in visa applications, which not yet taken effect, calling it “vague and ill‐defined.”

The groups complained the policy would prevent international students and educators “from contributing their talents to the United States.”

“This would cause disproportionate harm to the United States’ higher education system and research enterprise, suppressing our nation’s ability to innovate and be both globally collaborative and competitive,” they wrote. “These new barriers to entry risk the United States’ global pre-eminence as the international leader in scientific collaboration and research, further widening our nation’s innovation deficit, and sending a message to the rest of the world that international academic talent is not welcome here.”