The Minnesota Attorney General's Office will remain in Democratic control, as it has for decades, with Keith Ellison headed into a second term vowing to protect people's pocketbooks, help keep them safe and maintain abortion access.

The DFL incumbent eked out a victory over GOP political newcomer Jim Schultz, who had the backing of police and spent months elevating public safety concerns.

In one of the state's tightest contests, the outcome of the race wasn't formally called until Wednesday afternoon. Ellison won by roughly 20,000 votes, a margin of less than 1%, but larger than the threshold for a publicly funded recount.

"We've been through some tough times. But when the times get hard, the tough get strong," Ellison told supporters in the early hours Wednesday, pointing to COVID-19, the overturning of Roe v. Wade and the death of George Floyd during his first term. Ellison oversaw the prosecution of former Minneapolis police officer Derek Chauvin for Floyd's murder.

"We decided to get out there and we decided to reach out to each other. And while others were trying to have Minnesotans turn on each other, we turned to each other," Ellison said.

Precinct results show Ellison fared well in the metro, northeast Minnesota and some other regional centers. However, he trailed DFL Gov. Tim Walz in many suburban communities. Much of rural Minnesota voted for Schultz, who had particularly high margins in the state's central and southwestern areas.

Ellison, 59, the former Fifth District congressman and Democratic National Committee deputy chair, has long had a reputation for driving turnout. He said before the election that supporters were putting in 14-hour days as they raced to make sure people showed up at the polls. He likely also benefited from the lack of a third-party candidate in this year's race. In 2018, a Grassroots-Legalize Cannabis candidate drew nearly 6% of the vote.

Schultz announced Wednesday afternoon that he would call Ellison to congratulate him.

"We received the highest percentage of the vote for a Republican candidate for constitutional office in nearly 30 years," Schultz said in a statement. "We received substantially more total votes than any Republican candidate for constitutional office in Minnesota's history. We carried 76 of Minnesota's 87 counties. We didn't quite get there, but we have a lot to be proud of."

The GOP candidate had previously worked as an attorney for investment firm Värde Partners, and said he will be returning to the private sector.

Schultz's bid had centered on fighting crime and supporting law enforcement, and in his concession announcement he thanked police for supporting his campaign.

"It is among the great honors of my life to have gained more support from law enforcement than any candidate in Minnesota's history," he said.

Throughout his campaign Schultz took aim at Ellison for supporting the Minneapolis ballot amendment that would have replaced the city's Police Department with a public safety agency, saying Ellison backed "defunding" police.

Ellison ran on a broad campaign message that included highlighting his consumer protection initiatives, gun-safety efforts and work to take on pharmaceutical corporations.

"We connected with voters across the state about Keith's accomplishments and positive record of protecting Minnesotans' pocketbooks from corporate greed and protecting their freedoms like the right to abortion," campaign spokeswoman Faisa Ahmed said. "We also exposed the race-based fear, division and deception our opponent was running on, which Minnesotans have seen right through."

Protecting abortion rights in Minnesota — affirmed by the state Supreme Court ruling Doe v. Gomez — was also a pillar of Ellison's platform as surrounding states have restricted abortion access.

Anger over the fall of Roe boosted turnout and support for Democrats across the nation. In Minnesota, it helped the DFL gain control of the state Senate, House and governorship.

"Doe v. Gomez protects Minnesotans, but only so long as we have an attorney general who would fight for Minnesotans and who would fight to uphold that precedent," DFL House Speaker Melissa Hortman said Wednesday. "The attorney general is just an absolutely pivotal race."

Hortman said lawmakers could codify abortion protections into law in next year's legislative session.

In his speech to supporters Wednesday, Ellison hearkened back to 2012, when voters rejected a constitutional amendment to ban same-sex marriage. The following year, he noted, Democrats took control of state government and cleared the way for same-sex marriage.

"Better things are right within our future, my friends," Ellison said.

Data journalist Jeff Hargarten contributed to this report.