Flexing the power that comes with significant majorities in both chambers, the Democrat-controlled Maine Legislature elected Democrats on Wednesday afternoon to three of the most important positions in state government.

The House and Senate jointly elected Rep. Aaron Frey, D-Bangor, to succeed Gov.-elect Janet Mills as attorney general. Matt Dunlap will serve another term as secretary of state, and Democrat Henry Beck, a former state representative from Waterville, will replace independent Terry Hayes as treasurer.

Each will serve a two-year term. This is his fourth consecutive term, so Dunlap would be prevented from running for secretary of state again in 2020 because Maine’s term limits law applies to constitutional offices.

Troy R. Bennett | BDN

Troy R. Bennett | BDN

Maine Secretary of State Matthew Dunlap shakes hands after the Legislature elected him to another term on Wednesday in Augusta.

Maine Democrats surged to power after winning 110 of 186 legislative seats in the November election, largely seen as a referendum on President Donald Trump and outgoing Gov. Paul LePage, whom Frey addressed in a speech after his election.

A defense attorney from Bangor, Frey, 39, effectively won the seat in a five-way race among Democrats on Tuesday. Democrats in the new Legislature took four ballots to choose him over Tim Shannon of Falmouth, former Sen. Mark Dion of Portland, former attorney general and current Sen. Mike Carpenter of Houlton, and Augusta resident Maeghan Maloney, who serves as district attorney in Kennebec and Somerset counties.

Frey won his fourth term in the Maine House last month. A special election to fill his now vacant seat is likely to take place in February.

On Tuesday after his nomination, Frey said one of his first goals is to find better ways, with the help of the criminal justice system, to fight Maine’s opioid crisis.

Troy R. Bennett | BDN

Troy R. Bennett | BDN

Former state Rep. Henry Beck accepts applause from the Maine Legislature on Wednesday in Augusta after it elected him state treasurer.

Challenging Beck was independent Buckfield resident Terry Hayes, the outgoing treasurer who led an unsuccessful bid for governor this year. Hayes was the only nominee for either of the three positions put forth by Republicans.

Beck said Wednesday afternoon he was “appreciative and honored” to be elected treasurer. He’s already begun working on a transition plan with Hayes, he said, and hopes to continue with many of her initiatives from the past two years, including operating with transparency and in a bipartisan manner.

Dunlap, unsurprisingly, kept his title as secretary of state. He was the only contender for the post, after Republicans said they would not be nominating a challenger. It is his seventh term overall as secretary of state.

Though Dunlap said he’s the “least likely” person to ever hold the position, he’s “very gratified,” to be re-elected. Serving as secretary of state, he said, has been “one of the greatest things I’ve ever done.”