RICHMOND, Va.-- Former President Barack Obama is set to return to the campaign trail for the first time since he left office with a rally to help Democrat Ralph Northam in Virginia's closely watched race for governor.

The Northam campaign announced Wednesday that the lieutenant governor and Obama will appear together at an event in Richmond on Oct. 19.

The focus of the rally will be "the need for the next governor to create economic opportunity for all Virginians," according to Northam's campaign.

Obama has largely stayed out of the political spotlight since leaving office in January. But Virginia is one of only two states electing new governors this year and the swing state's contest is viewed as a possible early referendum on President Donald Trump, who has tried to undo many of Obama's signature legacies.

The next Virginia governor also will have a key role in the state's next redistricting, an issue that's been a post-White House priority for Obama.

The former president won Virginia both in 2008 and 2012. Northam will need many of Obama's supporters, particularly African-American voters, to turn out in the off-year election in order to be successful against Republican Ed Gillespie.

Most polls have shown a close race between Northam, a low-key pediatric neurologist, and Gillespie, the former chairman of the Republican National Committee and White House adviser to former President George W. Bush.

Trump recently endorsed Gillespie in a tweet, but has otherwise not been directly involved in the race. Gillespie has largely kept Trump at an arm's distance throughout much of the campaign and has declined to say whether he would invite Trump to campaign with him.

But Gillespie is close to Vice President Mike Pence, who is set to campaign with him on Saturday. Obama's vice president, Joe Biden, will campaign with Northam the same day.

Gillespie has also turned to Bush to help fundraise and Northam recently had a fundraiser with Hillary Clinton.

Election Day is Nov. 7