NEW YORK - The U.S. government did not violate the Constitution when it kept a Muslim scholar from entering the country for making charitable donations to a terrorist group, a judge ruled yesterday.

U.S. District Judge Paul A. Crotty said the government had shown that it excluded Tariq Ramadan for legitimate reasons.

Ramadan, a visiting fellow in Oxford, England, has spoken at Harvard University, Stanford University and elsewhere, but his visa was revoked in August 2004.

On Sept. 16, 2005, Ramadan requested a nonimmigrant visa that would permit him to attend speaking engagements, but he was excluded on the grounds that he aided a terrorist group by making charitable contributions from 1998 to 2002.

The American Civil Liberties Union argued in a lawsuit that Ramadan was being excluded for his political views.

Ramadan has opposed the U.S. invasion of Iraq, and said he sympathizes with the resistance there and in the Palestinian territories. He also has said he has no connections to terrorism, opposes Islamic extremism, and promotes peaceful solutions.

Ramadan has said he never intended to aid terrorism when he made $1,336 in contributions to the Association de Secours Palestinien. The U.S. government says the group has provided funds to Hamas, which the government has designated a foreign terrorist organization.

The United States did not outlaw contributions to the group until 2003. The ACLU has said Ramadan believed he was donating money to a group that was aiding education and orphanages, not terrorism.

But Crotty said the law requires Ramadan to provide "clear and convincing evidence" that he lacked knowledge of the group's illicit activities.

Jameel Jaffer, director of the ACLU's National Security Project, said the ACLU expected to appeal. Government lawyers did not immediately comment.