A Palestinian student from Lebanon who was set to begin his freshman year at Harvard was denied entry to the United States after immigration officials objected to his friends’ social media posts, he said this week, prompting furor among free-speech advocates.

The student, Ismail B. Ajjawi, 17, landed at Logan International Airport in Boston on Friday, and was turned back by a Customs and Border Protection agent, according to an account he gave The Harvard Crimson, a student newspaper.

Mr. Ajjawi, a resident of Tyre, Lebanon, said in the account that his phone and laptop were searched and that he was questioned at the airport about his friends’ social media activity. He wrote that an agent had yelled at him and “said she found people posting political points of view that oppose the U.S. on my friend list.”

He told the agent that he should not be held responsible for others’ posts, the statement said.

“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,” he wrote.