PLEASANT HILL — In a settlement approved Monday, Pleasant Hill will pay $400,000 to cover attorney fees for the groups that challenged the city’s gun law, ending a three-year legal battle.

The city noted that the outcome preserves its authority to regulate firearms dealers, while the plaintiffs said they had protected gun dealers’ ability to operate in Pleasant Hill.

In November 2013, a divided City Council voted to require a police permit for gun dealers, and to restrict where new sellers can operate in relation to schools, day care centers, parks and other businesses.

The National Shooting Sports Foundation, a gun industry trade group based in Newtown, Conn., and City Arms East, a Pleasant Hill gun store, sued the following month.

Under the original ordinance, gun stores cannot locate within 150 feet of a residence; within 500 feet of a park; or within 1,000 feet of a day care center or school. Store owners and employees must pass a criminal-background check.

The plaintiffs dropped the lawsuit in February after the city eased some of the restrictions on gun dealers, but they subsequently filed a claim to recover nearly $1 million in legal fees, according to the city. The $400,000 payment will come from the city’s $14.3 million reserve fund.

A San Francisco law firm represented Pleasant Hill pro bono.

“When the City Council initially adopted the firearms ordinance, the goal was to protect the health and safety of our citizens by putting in place reasonable regulations for firearm dealers to operate safely in Pleasant Hill,” the city said in a written statement.

“Although the city believes it has strong arguments for why the NSSF and City Arms East are not entitled to any attorney fees in this matter, in the interest of moving on to other priorities for our community, we have agreed to cover a portion of the challengers’ legal fees,” the statement continued.

The plaintiffs had alleged that by restricting where gun stores may operate, the firearms law actually was a zoning ordinance that should have been reviewed by the Planning Commission before the council approved it. Although Pleasant Hill maintained that it had not violated the state zoning law, in June 2014 the council amended the zoning ordinance to incorporate the location restrictions included in the firearms law.

But the lawsuit dragged on for another year. In an effort to resolve it, last December the council removed the distance requirements between gun stores and massage parlors, adult businesses and other gun dealers; prohibited firearms sales from residences and further relaxed location restrictions by allowing gun stores to open in commercial areas if the applicant proves any part of the parcel complies with the law’s distance provisions.

The changes also clarified that existing gun dealers are exempt from the location restrictions and would remain so even if the business expands or relocates within the same shopping center or site or if it is sold. In addition, the council prohibited gun stores within 1,000 feet of a college or university and added a provision allowing a person who is arrested, but not convicted, to sell guns in Pleasant Hill.

“We were successful in our goal to protect the ability of federally-licensed firearms retailers to open, operate and grow their businesses in the city of Pleasant Hill,” Lawrence G. Keane, NSSF senior vice president and general counsel, said in a statement.

“As we predicted when the city council made its unfortunate decision to go forward with an ordinance, which only put into place duplicative, unneeded regulation and did nothing to enhance public safety, it was very likely that taxpayers would be left paying the tab for what amounts to an unwarranted political decision to target law-abiding businesses.”