Through pay-negotiation workshops and partnerships with more than 100 companies, the city is trying to help female workers match the salaries of male counterparts.

On a cold, sunny morning in April, Boston’s mayor, Martin J. Walsh, took the podium in front of an audience of 150 corporate executives who had gathered at a downtown hotel to learn how men can be better allies to women at work. He quickly launched into one of his favorite stories, about a woman who approached him in an elevator to thank him for her recent $20,000 pay raise.

The kicker: He’s not her boss. Instead, the woman got her raise after taking one of the free salary negotiation workshops that Boston has provided for women since 2016.

What happens when an entire city tries to close the gender pay gap? In the last few years, Mr. Walsh has doubled down on a commitment made in 2013 by his predecessor, Thomas M. Menino, to bring pay equity to the city’s workforce.

The Boston Women’s Workforce Council teams up with the area’s companies and institutions, including major ones like Morgan Stanley, Zipcar and the Massachusetts Institute of Technology, to help them figure out ways to advance women, which they share with one another in quarterly best-practice meetings. The city has also trained over 7,000 women in salary negotiation, with a goal of training an additional 78,000 by 2021. A more immediate deadline: The Massachusetts Equal Pay Act, passed by the legislature in 2016, goes into effect in July.

The law states that “no employer shall discriminate in any way on the basis of gender in the payment of wages, or pay any person in its employ a salary or wage rate less than the rates paid to its employees of a different gender for comparable work.” In addition, it prohibits employers from disciplining workers for discussing their salaries with colleagues or asking job applicants for their salary history.

Massachusetts is not the first state to pass a pay equity law. In recent years, many states have been working to pass or strengthen their laws, including North Dakota, Illinois, and Oregon. But none of those states has gone quite as far as Massachusetts.

With employers, workers and policy all working toward the same goal, Boston is trying to succeed in an arena where decades of advocacy, research and good intentions have failed.

“If we just had the legislation, and employers weren’t acting and women weren’t asking, then it’s going to close the gap a little bit but not enough,” said Megan Costello, executive director of the Mayor’s Office of Women’s Advancement. “It has to be all of these things together.”

A report last year by the Boston Women’s Workforce Council, a public-private partnership, examined data from 114 companies that have pledged to close any pay gaps in their firms, covering 16 percent of the workers in the city, or nearly 167,000.

It showed that women earned an average of $73,327 to men’s $97,062, or 76 cents to the male dollar, less than the national average of about 80 cents. (As with recently released pay data from Britain, the gap can be partly explained by the higher concentration of men in senior roles.)

If progress in closing the pay gap over the past five decades continues at the same rate, women in the United States will not reach pay parity until 2059, the Institute for Women’s Policy Research has calculated.

But people in Boston say a change in their city may come earlier.