AUGUSTA, Maine — About a week before Election Day in 2010, a national group focused on electing Republicans to state legislatures poured $400,000 into five key Maine Senate races, unleashing a barrage of mail pieces and TV and radio ads that attacked the Democratic candidates and boosted the Republican contenders.

While the $400,000 spent by the Republican State Leadership Committee likely wasn’t the only factor, Republicans won all five targeted Senate seats. The victories were enough to swing the state Senate to Republican control for the first time in 16 years.

It’s likely that Maine Democrats — and other players in Maine’s 2012 legislative elections — learned a key lesson about campaign spending from the 2010 election cycle. They applied what they learned this year, when Democrats reversed the results of two years ago and took decisive control of both legislative chambers.

“This time, both sides brought a gun to a knife fight,” said Emily Shaw, a political science professor at Thomas College in Waterville. “You had real parity because you had money to respond to what had been, in 2010, unanswered opposition spending.”

Spending on state legislative races by political parties and political action committees shattered records this year. The more than $3.5 million third-party groups spent during the 2012 election cycle squashed Maine’s previous record for outside spending, $1.5 million, set in 2010.

Democrats were prepared for a higher-spending campaign season this year. According to data from the Maine Ethics Commission, the party poured nearly $885,000 into legislative races. Democrats also received substantial help from a newly formed, largely union-funded political action committee, the Committee to Rebuild Maine’s Middle Class, which sunk $758,000 into a range of races, all to help Democrats.

While the Maine Republican Party spent more on legislative races than the Democratic Party — about $921,000 — the GOP didn’t have the same help from other Republican-leaning committees. The second largest Republican spender, the Senate Republican Majority PAC, devoted $304,000 to Senate races.

“I think that last time, it was a surprise,” Shaw said of large amounts of third-party spending. “That’s why there was only effective spending on the Republican side.”

The Democrats’ legislative victories on Tuesday weren’t purely the result of higher spending, said Maine Democratic Party chairman Ben Grant.

“It starts with the hard work of our candidates,” he said. “They’re the ones who committed to [knocking on] more doors than our party had ever done before.”

That’s not to say the money didn’t have a major effect.

“I think we made good decisions about where to put our money,” Grant said. “I think the investment was in our ability to tell our story about the last two years and educate the people of Maine about what the Republicans did when they had total control, and to tell our story about what we would do if we got back in there.”

Of the $3.5 million the parties and other groups spent on the state’s 186 legislative races, they devoted 70 percent of it to 10 state Senate races and 10 House contests. The Democrats and allied groups outspent Republican forces in seven of the 10 most expensive Senate races and won six of those 10 races, defeating four incumbent Republican senators.

Democrats won in the most expensive state Senate race in District 32, where Democrat Geoffrey Gratwick of Bangor defeated first-term Republican Sen. Nichi Farnham. Democratic forces poured $247,000 into that race, according to the Maine Ethics Commission; Republicans spent $207,000. Both parties spent the majority of their money on negative advertising.

In the House, Democrats spent more money in eight of the 10 most expensive matchups and won six of those 10 contests.

Elevated Democratic spending is what made the difference in 2012, said Maine Republican Party spokesman David Sorensen. The Republican Party, he said, had internal polling about a month before Election Day showing only a few vulnerable GOP incumbents.

“We were confident at that point, and in the last several weeks we saw an influx of Democratic spending on negative ads that we couldn’t match,” Sorensen said.

Aside from spending more, Democrats seemed to focus their funds on a handful of key races. Especially in the Senate, those races were key to the Democrats taking back control from the GOP.

“The entire team came to the decision that, we’re going to find the districts where we feel we have the best chance,” said Stefan Hankin, president of Washington, D.C.-based Lincoln Park Strategies, a firm that worked with Maine Democrats on state Senate campaigns. “We’re going to try to make it happen there. That’s going to give us the best shot, versus going to 15 to 20 districts.”

Democrats started a TV and mail campaign in early August that labeled five Republican state Senate incumbents “rubber stamps” for Gov. Paul LePage’s agenda. Democrats continued to target those districts throughout the campaign season with additional mail pieces, radio ads and television spots.

All five of those Senate races — of which Democrats won four — landed on the top 10 list for the most expensive Senate contests.

“What they weren’t looking for was the rubber stamp state Senate,” Hankin said of voters in Maine and across the country. “We need someone who’s actually going to do the work here, not just blindly do the bidding of what governors are saying.”

To view the top 10 spending districts in the state House and Senate, click here.