As a few in the crowd shouted “marriage” and “Do you support it?” at him, President Obama on Thursday evening avoided taking a position on a measure being considered by the New York state legislature that would legalize gay marriage. Instead he said, “I believe that gay couples deserve the same legal rights as every other couple in this country.”

For months, Obama has insisted his position on gay marriage is “evolving” but has not shifted from his previously stated view that marriage is between a man and woman. But in a coincidence of timing, the president arrived at a downtown Manhattan hotel for a long-scheduled fundraiser put on by gay and lesbian activists as the legislature in Albany was on the verge of voting whether New York will become the sixth state to allow gay marriage.

“We’re going to keep on fighting until the law no longer treats committed partners who’ve been together for decades like they’re strangers,” Obama told a crowd of more than 600, many of whom had come from other states to attend his first fundraiser specifically for gays in the 2012 election cycle.

He acknowledged the New York legislation, saying “right now I understand there’s a little debate going in New York.” But as some urged him to support the legislation, Obama would not.

“New York is doing exactly what democracies are supposed to do. There is a debate; there is deliberation,” he said, refusing to declare a view on the bill or encourage other states to take similar action.

It was not clear how many people in the room were shouting at Obama on gay marriage. But they were loud, at one point yelling “marriage” enough times that the president stopped speaking and said, “I hear you guys.”

“Believe it or not, I anticipated” this, Obama said to laughter from many in the crowd.

While not saying explicitly that he supported gay marriage, Obama likened the heckling he received Thursday to earlier in his term, before he signed the repeal of the “don’t ask, don’t tell,” policy that forbade people who are openly gay from serving in the military.

Although the repeal finally passed Congress in December, Obama said, it was a long process, and gay marriage would follow a similar pattern.

“Yes, I expect continued impatience with me on occasion,” he said, acknowledging the hecklers. “There should be impatience when it comes to the fight for basic equality.”

The appearance was part of three fundraisers the president squeezed into a short evening trip to Manhattan. People from at least 22 states came for the gay and lesbian event, according to organizers, donating from $1,250 to $35,800 (the legal maximum) to Obama’s campaign and the Democratic National Committee to attend.

Actor Neil Patrick Harris was the emcee, and a number of other prominent actors attended. During a speech before Obama spoke, Harris reeled off a long list of administration accomplishments, from the president’s decision to stop enforcing the Defense of Marriage Act to his appointment of transgender Americans to government posts.

“We have made incredible progress the last few years,” Harris said.

Harris did not mention gay marriage, an issue on which Obama has a complicated history. In 1996, as a candidate for the Illinois state Senate, Obama signed a questionnaire saying he backed gay marriage. But in his 2008 presidential campaign, he refused to adopt that stance, saying marriage was between a man and a woman.

In December, as his administration was pushing through the repeal of “don’t ask, don’t tell,” Obama said his views on gay marriage were “evolving.”

Some gay-rights activists say that stance, while not ideal, should not be the sole judge of Obama’s record on gay rights, pointing to his other accomplishments.

“I believe his heart is in the right place,” said Thomas Gerace, a Boston entrepreneur who attended the event.

But others argue Obama should just say he backs gay marriage, adding that the president’s “evolving” position is a political move to avoid turning off more conservative voters.

“The time is now. The president is really lagging behind the American people,” said Evan Wolfson, who runs a New York-based group called Freedom to Marry.

The push for Obama to support gay marriage and the potential adoption of the law in New York comes amid a shift in public opinion on the issue. In 2004, 11 states passed laws banning gay marriage, and polls showed a majority of the public opposed gay marriage. Now some surveys show a small majority of the public supports gay marriage.

The issue does not fall purely on partisan lines, although Democrats are far more supportive of gay marriage than Republicans. Moves to legalize gay marriage have generated opposition from some black and Latino religious leaders who traditionally support Democrats. And Republicans must balance their need to maintain support among religious conservatives, many of whom oppose gay marriage, with appealing to voters younger than 35, the age group that most enthusiastically backs gay marriage.

This week, former Utah governor Jon Huntsman Jr., a GOP presidential candidate, said he would not oppose the New York law, saying the matter should be left up to each state. At the same time, most of the GOP presidential candidates would support a constitutional amendment defining marriage as between a man and a woman.