A federal judge ruled that a popular imam accused of terrorist connections could stay in the United States indefinitely.