Democrat Manka Dhingra. (Elaine Thompson/AP)

Democrats gained a majority in Washington's state Senate this week, securing control of all branches of governments in the three states along the West Coast.

With most mail ballots counted, Democratic prosecutor Manka Dhingra won the race in Washington's 45th District over Republican Jinyoung Lee Englund, a former Capitol Hill staffer, after a campaign that cost both candidates and a swarm of outside groups nearly $9 million. The Associated Press called the race on Thursday afternoon.

Dhingra's victory puts Democrats firmly in command of a state that had been trending bluer and will allow the party to pursue a progressive agenda that had been bottled up by Republicans.

Democrats have won at least 27 state legislative seats across the country since the start of the year, marking a turnaround after losing more than 1,000 legislative seats during the Obama years.

"We've put the last brick in the big blue wall against the Trump agenda, across the whole West Coast," said Washington Democratic Party Chairwoman Tina Podlodowski. "We have $4 billion in projects that were held up by the Republican senate — 19,000 jobs that can now get started. We can fully fund K-12 education. We'll look at affordable housing, health care and making voting fairer."

Dhingra had run specifically on enabling Democrats to pass that agenda, telling voters in one of her last debates with Englund that they could "change the fact that we're not governing." The Republican warned that total Democratic control of the state would lead to surging tax rates; her TV ads showed smug Seattle residents getting ready to impose their values on the suburbs.

But the surge of outside money into the race largely benefited Dhingra. Democrats attacked Englund over her support from Republican groups and publicized a tweet in which the nominee had praised President Trump. Dhingra largely avoided a backlash for her outside support; Michael Bloomberg and Tom Steyer, billionaires who have upped their investments in progressive causes, each gave $250,000 to the Democrat.

"Manka Dhingra's critical win means the Washington state Senate will be led by strong supporters of important environmental protections, opening the door to legislative action on climate change — something that will benefit . . . Washington's economy and the health and safety of everyone who resides there," Steyer said in a statement.

Tuesday's victory made Washington the eighth state run by a Democratic "trifecta," with the party in control of the governor's mansion and both houses of the state legislature.