Representative Charles B. Rangel, seeking a 23rd term, held a slim lead in a fierce battle early Wednesday with State Senator Adriano D. Espaillat in their primary election contest, a rematch that was largely fought along ethnic and generational lines.

With 100 percent of precincts reporting after 1 a.m., Mr. Rangel led by just over 1,800 votes, or 47.4 percent to 43.6 percent.

Absentee ballots and affidavit ballots filed by voters at polling stations could determine the outcome of the race. As of Tuesday night, the New York City Board of Elections said it had given out 2,834 absentee ballots, of which 903 were returned so far, and 738 of those deemed valid. Absentee ballots must be received by the board no later than next Tuesday in order to be counted. No count of affidavit ballots was immediately available.

Mr. Rangel, 84, a powerhouse in New York politics for nearly half a century who long exerted Harlem’s influence on the national stage, was seeking the chance to retire on his own terms after a career that spanned the civil rights era and the election of a black president. For Mr. Espaillat, 59, a victory would secure him a place in history as the first Dominican-born member of Congress.