MARYLAND ATTORNEY General Douglas F. Gansler, who is running for the Democratic nomination for governor, has called on his primary opponents to join a pact to impede outside spending in the race. Mr. Gansler’s proposal may be self-interested, but it is also an excellent idea for Maryland. The other declared primary candidates, Lt. Gov. Anthony G. Brown and state Del. Heather R. Mizeur (Montgomery), should endorse it.

Yes, Mr. Gansler is likely motivated, partly or mainly, by the fact that Mr. Brown, the putative front-runner, has racked up endorsements from powerful labor groups. That means that Mr. Gansler may end up being the main target of vicious super-PAC ads and direct mailings. But Mr. Brown and Ms. Mizeur are not immune; once the outside-funded ad wars are ignited, everyone is fair game.

Mr. Gansler’s idea is modeled on the “people’s pledge” taken by the 2012 U.S. Senate candidates in Massachusetts, Scott Brown and Elizabeth Warren. In an age when super PACs and other outside special interests have almost unlimited budgets for political spending — much of it unregulated, unrestricted and unidentified by source — they agreed the race would be better off without a tsunami of negative advertising from outsiders.

Technically, the pact is unenforceable. But under the pledge in Massachusetts, candidates agreed to donate 50 percent of the amount of any outside ad buy to a charity of the other candidate’s choice. That seemed to do the trick. In the Brown-Warren race, outside spending dried up.

After the race, which was won by Ms. Warren, Common Cause analyzed the effects, comparing spending from all sources in Massachusetts to spending in three other Senate races in Virginia, Ohio and Wisconsin. The findings were stark. While the Massachusetts candidates outspent outside groups by about 10 to 1, outside groups heavily outspent the candidates in the other three races. In the Virginia contest between Republican George Allen and Democrat (and now-Sen.) Timothy M. Kaine, outside groups accounted for 62 percent of all spending.

Compared with Massachusetts, the other three states also ended up with vastly greater amounts of spending by groups whose donors were undisclosed. And while the total contributions of small donors (of less than $200) outmatched spending by outside groups in Massachusetts, they were dwarfed by the outside groups’ outlays in the other three states.

The bottom line was clear: The Brown-Warren pledge helped keep that race focused on the candidates, ideas and issues. And it removed a deluge of mostly negative messaging, uncontrolled by the candidates, from the public domain.

Maryland candidates would be wise to follow suit. Given the Democrats’ domination of state politics, the contestants in the current primary don’t have to worry much about being hamstrung by the pledge in a general election, where the Republicans show no sign of being able to mount a serious challenge. And capping donations may also help the eventual winner to maintain a degree of independence from interest groups.

The Massachusetts pledge set a healthy precedent. Since the Brown-Warren contest, several other campaigns in the state have followed suit. Let’s hope it becomes the norm.