Turner Broadcasting Systems and Interference Inc. agreed Monday to pay $2 million for an unconventional Cartoon Network advertising campaign last week that caused a widespread bomb scare, Attorney General Martha Coakley announced.

The agreement with several state and local agencies resolves any potential civil or criminal claims against the companies, Coakley said during a news conference attended by a host of public officials, including Boston Mayor Thomas Menino, Somerville Mayor Joseph Curtatone and Cambridge Mayor Kenneth Reeves.

More than three dozen blinking electronic signs with a boxy cartoon character giving an obscene hand gesture were found Wednesday in the three cities. The signs, part of a publicity campaign for Cartoon Network's "Aqua Teen Hunger Force," also appeared in nine other major U.S. cities in recent weeks, with little interest.

But in Boston, bomb squads responded to reports of the devices near a subway station, on bridges and elsewhere.

Authorities say two men were paid to hang the signs around the city. Peter Berdovsky, 27, and Sean Stevens, 28, have pleaded not guilty to placing a hoax device and disorderly conduct. Coakley said prosecutors were in discussions with the men's attorneys to resolve the charges before a trial.

"We are fortunate that no one was injured," Coakley said. "We hope that this painful lesson will not be lived or learned again either by the communities involved or ... Turner Broadcasting and Interference. In one sense, all's well that end's well and we hope shortly we can put this behind us, but trust that this kind of episode won't be repeated all the while understanding that we can be no less diligent as perceived threats occur in the future."

Turner Broadcasting, a division of Time Warner Inc., and Interference Inc., a New York City-based marketing company, also issued a public statement accepting full responsibility and apologizing for the "unconventional marketing tactic" and for hardships caused to Boston area residents.

"We understand now that in today's post-Sept. 11 environment, it was reasonable and appropriate for citizens and law enforcement officials to take any perceived threat posed by our light boards very seriously and to respond as they did," the statement said.

The companies also said they were reviewing their policies concerning local marketing efforts and strategies to ensure they are not disruptive or perceived as threatening.

Coakley said she did not know how the two companies would divide responsibility for the payment, which was being wired to the attorney general Monday.

As part of the settlement, $1 million will be used to reimburse the agencies and $1 million will be used to fund homeland security and other programs.

Boston, for example, will receive $140,232 in direct service reimbursements, $102,063 in other restitution and $242,295 in homeland security money. The MBTA, whose commuter services were disrupted by the investigation, will get the largest homeland security grant — $315,198. That is on top of $182,426 in reimbursements and $132,772 in restitution.

MBTA General Manager Daniel Grabauskas and Joseph Carter, the chief of the MBTA police, assured the public the money would not be spent on overtime or other intangible expenses.

"We will develop a list of meaningful and effective homeland security and customer safety programs that will have an enduring effect on our customers," Carter said.

Menino also struck back at late-night comics and others who have accused municipal officials of overreacting.

"Shame on them," the mayor said.

Coakley, meanwhile, defended settlement talks with Berdovsky and Stevens, who initially attracted some sympathy but were criticized after insisting on talking about hair styles of the 1970s during a news conference following their court hearing Thursday.

"What they did afterwards can't influence us as prosecutors," Coakley said.