AUGUSTA –– The state’s top law official and top election official will retain their jobs for another two years, but there will be a new treasurer after Wednesday’s election in the Legislature.

Democrats, who have exactly half of the members in the House and Senate, were joined by just enough independents to re-elect Attorney General Janet Mills and Secretary of State Matt Dunlap. Former state Rep. Terry Hayes, nominated by Republicans on Tuesday, defeated Neria Douglass in a secret ballot vote by the joint convention.

The Democratic caucus held together to fight off Republican challenges from William Logan for attorney general and Jonathan Courtney for secretary of state. However, it couldn’t protect Douglass. Hayes was considered the toughest challenger because she had the potential to peel off enough of her former Democratic colleagues.

Republicans on Tuesday took the unusual step of nominating Hayes, a move that could fuel future attempts to drive a wedge in their caucus and diminish their influence in negotiating the state’s next two-year budget and other proposals of significance.

LePage had made defeating Mills a personal priority. The governor has clashed with her a number of times and has said that her re-election would signal Democrats’ unwillingness to work with him during his second term. He’s also advocated for changing the way Maine elects the attorney general.

Maine is the only state in which the Legislature elects its top law official, according to the National Association of Attorneys General. Forty-three states and the District of Columbia popularly elect their attorneys general, and the position is appointed by the governor in five states. In Tennessee, the Supreme Court fills the position.

Tensions between Mills and Republican Gov. Paul LePage have prompted the governor and others to suggest that Maine should change its constitution so that the position is popularly elected as it is in other states. A change to the constitution would require support of two-thirds support of the Legislature and approval from voters.

Moving to a popularly elected attorney general could invite spending by outside interest groups attempting to influence future elections.

Earlier this year the Center for Public Integrity found that outside interest groups spent $8 million on 10 attorney general races in 2012, according to an analysis of data from the National Institute on Money in State Politics and state and federal campaign finance filings.

There are several reasons for the spending.

In Maine and other states, the attorney general serves in a number of capacities, including giving legal advice to state agencies, the governor and the Legislature. The office’s duties often collide with, and can advance, public policy, particularly if the legislative or executive branch asks the attorney general to find a legal reason to join or justify a proposal. That was the case in 2011 when Republican Attorney General William Schneider joined more than 20 other Republican-led states to challenge the Affordable Care Act.

Attorneys general also join and oversee consumer protection lawsuits on behalf of their states. One of the biggest spenders on attorney general races in 2012 was the U.S. Chamber of Commerce, whose business constituents could be affected by such lawsuits.

Additionally, popularly elected attorneys general are often considered future gubernatorial candidates.

A major spender in the 2014 election was the Republican Attorneys General Association, a tax-exempt group that raised over $7.4 million, according to data complied by the Center for Responsive Politics.