ALBUQUERQUE, N.M. (AP) — Democrats ran roughshod over Republican candidates in New Mexico's midterm election, taking control of the governor's office, flipping a key congressional seat along the U.S.-Mexico border, sweeping major statewide races and ensuring Democratic control of the state's top two courts.

U.S. Rep. Michelle Lujan Grisham won the governor's race in a landslide to succeed termed-out Republican Gov. Susana Martinez amid frustration over the state's struggling public education system, entrenched poverty and a boom-and-bust economy closely tethered to the oil industry.

Beyond New Mexico, Democrats appeared to gain unified control of the governor's office and both legislative chambers in Colorado, Illinois, Maine, Nevada and New York. Overall, Republicans still have more states with that trifecta of power.

Lujan Grisham defeated U.S. Rep. Steve Pearce, whose congressional district along Mexico's border ended up going to Democrat Xochitl Torres Small following vote counting that stretched into Wednesday evening. Torres Small vied for the seat with state Rep. Yvette Herrell, who embraced President Donald Trump's policies on immigration and won endorsements from conservative-leaning advocacy groups including the National Rifle Association.

Democrats also won elections for attorney general, secretary of state, state treasurer, state auditor and land commissioner, who oversees oil and renewable energy resources on vast state trust lands. They ousted a GOP Supreme Court justice and four appellate court judges.

The election positions Democrats to overhaul public education standards and funding, along with the state's approach to policies on climate change, gun control and the possible authorization of recreational marijuana.

On the campaign trail, Lujan Grisham vowed to push for new investments in solar and wind energy and has pledged to comply with a court order to help poor and minority students.

State Senate majority leader Peter Wirth of Santa Fe said Lujan Grisham's victory places statewide minimum wage and teacher pay increases at the top of the legislative agenda next year, and could revive vetoed and dormant initiatives on subjects from campaign finance to abortion rights.

House Speaker Brian Egolf said forecasts for a major budget surplus provide a "once in a multiple-lifetimes opportunity to completely re-invent education."

New Mexico has shifted between Republican and Democratic governors for three decades even though Democrats dominate voter registration rolls. Democrats also have maintained majorities in both legislative chambers for most of the last century.

Heavy currents of Roman Catholicism and a ranching ethos have helped Republican candidates win periodically over moderate or fickle Democrats on social issues or as a counterweight to the Legislature.

Political consultant and former Democratic state senator Dede Feldman said results of legislative races indicate a progressive political shift in traditionally Republican areas of northeast Albuquerque.

"Most of these candidates ran on health care and education. They didn't really try to nationalize the race," Feldman said.

Democratic legislative candidates seized control of districts held by retiring GOP Minority Leader Nate Gentry and Republican stalwart Larry Larranaga, who served for more than two decades.

Also in Albuquerque, they ousted Republican Reps. Monica Youngblood, an ally of the governor who was recently convicted of drunken driving, and seven-term Rep. Jimmie Hall.

At the same time, Trump weighed on voters' minds Tuesday, according to a wide-ranging survey of the electorate conducted by The Associated Press.

For 30 percent of New Mexico voters, President Donald Trump was not a factor they considered while casting their votes. By comparison, more than one-quarter said a reason for their vote was to express support for Trump, and 43 percent said they voted to express opposition to Trump.

A majority of New Mexico voters had negative views of Trump: About 60 percent said they disapprove of how he is handling his job as president, while 40 percent said they approve of Trump.

Democratic U.S. Sen. Martin Heinrich won re-election to second term, as Republicans held onto their Senate majority with wins against incumbent Democrats in Indiana, North Dakota and Missouri.

U.S. House races provided a historic win by Democrat Debra Haaland, one of the first Native American women elected to Congress. She will fill Lujan Grisham's seat. Five-term Democratic incumbent U.S. Rep. Ben Ray Lujan cruised to victory in his northern New Mexico district.