Maryland Democratic candidate Wes Moore won the state’s gubernatorial primary over former Barack Obama administration Labor Secretary Tom Perez late Friday night. 

The Associated Press declared Moore, a best-selling author and veteran, the winner three days after the polls closed Tuesday.

Moore beat out several high-profile Democrats, including Perez who as the former Democratic National Committee chair had the backing of top Democrats like Speaker of the House Nancy Pelosi and other Maryland state officials. 

Wes Moore

FILE - Maryland Democrat Wes Moore talks to reporters on June 6, 2022 in Owings Mills, Md., after a Democratic primary debate for governor of Maryland.  (AP Photo/Brian Witte, File)

BALTIMORE STATE'S ATTORNEY MARILYN MOSBY LOSES RE-ELECTION BID IN DEMOCRATIC PRIMARY

Perez also released a TV advertisement in March that was narrated by an archived clip from when Obama was in office that introduced the Maryland candidate's background. 

The former president described him as "the son of immigrants" who "worked on the back of a trash truck to help pay for college" and championed his work as the Secretary of Maryland’s Department of Labor. 

It does not appear Obama endorsed Perez during his most recent campaign. 

Moore will now face off with Republican candidate Dan Cox who has been endorsed by Donald Trump. 

TED CRUZ SAYS TRUMP ANNOUNCING 2024 RUN WOULD ‘SIGNIFICANTLY’ CLEAR GOP FIELD

Though Maryland voted in Republican Larry Hogan in the previous two gubernatorial elections, Cox will likely face an uphill battle.

Tom Perez

Former Labor Secretary Tom Perez, is seeking the Democratic nomination for governor. (AP Photo/Brian Witte)

AFTER TRUMP-BACKED CANDIDATE VICTORIES, SOME DEMOCRATS QUESTION PARTY'S MEDDLING IN GOP PRIMARIES

Maryland has voted Democrat in every presidential election since 1992 and saw its highest percentage of voters turn out blue in the 2020 election where President Biden won by 65 percent of the vote.

Moore also saw his share of top-ranking Democratic support when the number two House Democrat, Rep. Steny Hoyer of Maryland, endorsed him for governor in April.

Oprah Winfrey held a virtual fundraiser for Moore last month and drew in 300 attendees with tickets ranging from $100 to $6,000, according to a local Fox News report.

Maryland election

FILE - From right, Rushern Baker, Wes Moore, Doug Gansler and Jon Baron stand at their podiums just before a debate of eight candidates seeking the Democratic nomination for governor of Maryland on Monday, June 6, 2022 in Owings Mills, Md.  (AP Photo/Brian Witte, File)

CLICK HERE TO GET THE FOX NEWS APP

Cox was declared the winner of the Republican primary Tuesday. 

But due to Maryland state regulations that prohibits mail-in ballots from being opened until the Thursday after the election, Moore’s win took several days longer to confirm. 

The Associated Press contributed to this report.