Hours before the beginning of Boston’s annual St Patrick’s Day parade on Sunday, the city’s mayor announced that he would not take part, because organisers banned gay groups from participating.

Marty Walsh confirmed in a morning statement that attempts late on Saturday to strike a compromise with parade organisers to allow a group of gay military veterans to march had collapsed.

“As mayor of the city of Boston, I have to do my best to ensure that all Bostonians are free to participate fully in the civic life of our city,” said Walsh. “Unfortunately, this year, the parties were not able to come to an understanding that would have made that possible.”

In registering his disappointment at the dispute, the mayor noted that “so much of our Irish history has been shaped by the fight against oppression”. He said he would be spending the day with his family.

Walsh’s decision came after the failure of a campaign by MassEquality, an LGBT rights campaign group in Massachusetts, to persuade the South Boston Allied War Veterans Council, which organises the parade, to allow the gay veterans to openly take part.

MassEquality requested that its members be allowed to carry banners and signs identifying themselves as gay. The veterans council would only permit them to participate if they made no reference to their sexuality, an offer that was rejected by the campaigners.

The organisers won the right to exclude certain groups from their parade under a unanimous decision by the US supreme court in June 1995. They had cancelled the 1994 parade when campaigners successfully sued in the Massachusetts courts to be allowed to participate.

The parade organisers have consistently argued that being forced to permit openly gay marchers would conflict with their belief, rooted in their Roman Catholic heritage, that homosexuality is immoral.

Amid particularly sharp anger this year about the controversial rule, dozens of state and city politicians said that they would be boycotting the parade. The Boston Beer Company, whose Samuel Adams brand has long sponsored the event, announced on Friday that it too was pulling out of this year’s event.

The company said in a statement that it had wanted a deal “that would allow everyone, regardless of orientation, to participate in the parade”.

The brewer’s boycott prompted Club Cafe, one of the city’s most popular gay bars for several decades, to reverse its well-publicised earlier decision to stop serving Sam Adams products due to their association with the parade.

Attention will now turn to New York, another of America’s most liberal cities. Its St Patrick’s Day parade, on Monday, also bars participants from openly stating that they are LGBT. Mayor Bill de Blasio has said that he will boycott the march, which is the world’s biggest St Patrick’s Day celebration, because of the rule.

Joan Burton, an Irish cabinet minister, said she had turned down an invitation to the parade as a protest against the exclusions. The Police Service of Northern Ireland has come under pressure over its planned participation in the parade.

The New York City council announced that it would not be attending in an official capacity because it was “committed to celebrating and respecting the diversity of New York City”.

“I hope the organisers will eventually realise that the parade will be better when all New Yorkers can march openly and proudly,” Speaker Melissa Mark-Viverito said in a statement. Some individual members are expected to attend.

In a mirror of the developments in Boston, Heineken, the sponsor of the New York event, withdrew on Friday, declaring: “We believe in equality for all.” The decision was welcomed by campaigners.

“Heineken sent the right message to LGBT youth, customers and employees who simply want to be part of the celebration,” Sarah Kate Ellis, the president of the gay rights group GLAAD, said in a statement.