By Elizabeth Barber

BOSTON, March 16 (Reuters) - Boston's Irish-American mayor will not march in the city's St. Patrick's Day parade on Sunday after failing to hammer out a deal with organizers to allow a group of gay and lesbian activists to march openly.

Mayor Marty Walsh had tried to negotiate a deal with organizers, the conservative Allied War Veteran's Council, to allow members of MassEquality, one of Massachusetts' largest gay activist groups, to join the parade.

"So much of our Irish history has been shaped by the fight against oppression," Walsh, the city's first Irish-American mayor in 20 years, said in a statement.

"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. Unfortunately, this year, the parties were not able to come to an understanding that would have made that possible."

Organizers of St. Patrick's Day parades in New York and Boston, among the most liberal-leaning cities in the United States, have come under increasing criticism in recent years for banning openly gay marchers.

Parade organizers argue that to do so would conflict with their Roman Catholic heritage. The Catholic church contends that homosexual activity is immoral.

New York Mayor Bill de Blasio also plans to boycott his city's parade, scheduled for Monday, in protest.

On Friday, two major beer companies, Sam Adams brewer Boston Beer Co and Heineken dropped their sponsorship of parades in Boston and New York, respectively, over the issue.

In Boston, Walsh had tried to reach a deal for MassEquality's members to march openly, rather than without any identification of their sexual orientation as required by parade organizers.

The invitation to MassEquality was subsequently rescinded by the parade organizers, who said they had been "misled" about the number of veterans in the gay and lesbian group.

Massachusetts in 2003 became the first U.S. state to legalize gay marriage. Attitudes on gay marriage have changed markedly across the nation since then, with 17 states and the District of Columbia now allowing same-sex couples to wed. (Editing by Scott Malone and Sophie Hares)