The subprime mortgage crisis isn’t the only calamity Wall Street created that’s upending the finances of U.S. states and cities.

For more than a decade, banks and insurance companies convinced governments and nonprofits that financial engineering would lower interest rates on bonds sold for public projects such as roads, bridges and schools. That failed promise has cost more than $4 billion, according to data compiled by Bloomberg, as hundreds of borrowers from the Bay Area Toll Authority in Oakland, California, to Cornell University in Ithaca, New York, quietly paid Wall Street to end agreements since 2008.

California’s water resources department this year spent $305 million unwinding interest-rate bets that backfired, handing over the money to banks led by New York-based Morgan Stanley. North Carolina paid $59.8 million in August, enough to cover the annual salaries of about 1,400 full-time state employees. Reading, Pennsylvania, which sought protection in the state’s fiscally distressed communities program, got caught on the wrong end of the deals, costing it $21 million, equal to more than a year’s worth of real-estate taxes.

“It was brilliant, and it all blew up on me,” said Brian Mayhew, chief financial officer of the Bay Area Toll Authority, the state agency that gave Ambac Financial Group Inc., the New York-based bond insurer that filed for bankruptcy this week, $105 million to end $1.1 billion of interest-rate agreements. The payments equal more than two months of revenue on seven bridges the authority oversees around San Francisco