In a 12-page ruling, Justice Edgar G. Walker of State Supreme Court in Brooklyn found that Ms. Teachout had lived in New York consistently enough to satisfy a five-year residency requirement detailed in the State Constitution.
Mr. Cuomo, who is seeking a second term, is expected to win his party’s nomination easily, and polls have shown him with an enormous lead in the November general election, where he would face Rob Astorino, a Republican who is the Westchester County executive.
But a strong showing in the primary by Ms. Teachout, a law professor who is appealing to liberals who have been vocal about their frustration with Mr. Cuomo on a variety of issues, could prove embarrassing to the governor. (A third Democrat, Randy Credico, a political comedian and activist, will also appear on the primary ballot.)