ALBANY — In a surprise vote, the New York State Senate on Monday rejected legislation that would have granted state tuition aid to undocumented immigrants, dealing a blow to immigrants’ advocates who had made it their top priority in the capital.

The Senate, controlled by Republicans and a small group of Democrats, failed to pass the measure despite a vote of 30 in favor and 29 opposed. It required 32 votes in favor to pass.

Immigrants’ advocates have been leaning on the Senate for months. But Republicans had shown no interest in considering the legislation, and the decision to hold a vote on Monday came abruptly, with almost no notice.

Even advocates were surprised: Latino activists who had planned to visit the Capitol on Tuesday to lobby for the measure said they would now use the trip to express their frustration.