Onyango Obama, half brother of the president's late father, came to the United States in 1963 from Kenya on a student visa that expired in 1970. He's been living in the country unlawfully ever since.
"He's so happy to stay here because he loves this country," Margaret Wong, Onyango Obama's attorney, said in a telephone interview after the court hearing.
During the hearing, Wong asked the 69-year-old liquor store manager whether he had any relatives in America. Obama said he had a sister, two nieces and a nephew.
Asked to name the nephew, he replied: "Barack Obama. He's the president of the United States."
Judge Leonard Shapiro ruled from the bench that Onyango Obama qualified for a provision in federal immigration law that allows immigrants who have lived in the United States since before 1972 and have "good moral character" to apply for legal permanent residency, also known as a "green card."
The judge said Obama was a good neighbor and a gentleman and had paid his taxes. At the end of the hearing, the judge said, "Welcome to America."
"He won it fair and square, not because he had a relationship" with the president, Wong said. If anything, she said, his ties to the president probably brought additional scrutiny and delayed the case.
David Leopold, an immigration lawyer based in Cleveland, said the judge had ruled properly under the law. "The law is so clear-cut that it wouldn't matter who he is related to. All you have to do is behave yourself and have been here since 1972," he said.
Obama had ignored a deportation order issued in 1992. His immigration status was not publicly known until he was arrested on suspicion of drunk driving in 2011 in Framingham, Mass., west of Boston. He allegedly told police at the time, "I think I will call the White House."
He testified Tuesday that he did not recall saying that to an officer. He attended an alcohol education class and paid fees, and the case ultimately was dismissed.
In his memoir, "Dreams From My Father," the president writes about his 1988 trip to Kenya and refers to an Uncle Omar. Onyango Obama also goes by Omar.
Onyango Obama said Tuesday that his nephew stayed with him for several weeks when he attended Harvard Law School.
Shapiro previously granted an asylum request for Onyango Obama's sister and the president's aunt, Zeituni Onyango, in 2010. She had been ordered deported in 2004 after her first asylum request was rejected.
She continued to live in public housing in Boston, however, and her status was revealed just before the 2008 election. At the time, then-candidate Obama said he did not know his aunt was living here illegally.
She attended the court hearing Tuesday, but Shapiro said he did not need to hear from her.