Barack Obama is returning to the campaign trail for the first time since he left office.

The former president will join a rally to help Democrat Ralph Northam in Virginia's race for governor.

Mr Obama and Mr Northam will appear together at an event in Richmond on 19 October.

“President Barack Obama said that ‘I want to tell you how important Virginia is to me. It means the world to me. It means our legacy, for me and Michelle. I’m going to do everything that I can to come to Virginia to campaign for you,’” Mr Northam told the crowd at a recent campaign event, the Richmond Times Dispatch reported.

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

Barack Obama and Donald Trump reacted to mass shootings quite differently

Mr Obama has largely stayed out of the political spotlight since leaving office in January, but recently denounced Donald Trump's repeated attempts to repeal Obamacare as "aggravating."

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 Mr Trump, who has tried to undo many of Mr Obama's signature legacies.

The former president won Virginia both in 2008 and 2012.

Mr Northam will need many of Mr Obama's supporters, particularly African-American voters, to turn out in the election in order to be successful against Republican Ed Gillespie.

Barack Obama's best moments in the White House Show all 11 1 /11 Barack Obama's best moments in the White House Barack Obama's best moments in the White House May 19, 2009 “The President was leaving the State Floor after an event and found Sasha in the elevator ready to head upstairs to the private residence. He decided to ride upstairs with her before returning to the Oval Office,” Peter Souza Barack Obama's best moments in the White House Oct. 26, 2012 President Barack Obama pretends to be caught in Spider-Man's web as he greets the son of a White House staffer in the Outer Oval Office Peter Souza Barack Obama's best moments in the White House “A National Security staffer, Carlton Philadelphia, brought his family to the Oval Office for a farewell photo with President Obama. Carlton’s son, Jacob, softly told the President he had just gotten a haircut like President Obama, and asked if he could feel the President’s head to see if it felt the same as his.” Peter Souza Barack Obama's best moments in the White House March 21, 2010 The President, Vice President and senior staff applaud after watching on television the House vote on H.R. 4872 for health care reform, in the Roosevelt Room of the White House Peter Souza Barack Obama's best moments in the White House Dec. 3, 2009 President Barack Obama fist-bumps custodian Lawrence Lipscomb in the Eisenhower Executive Office Building following the opening session of the White House Forum on Jobs and Economic Growth Peter Souza Barack Obama's best moments in the White House Sept. 22, 2015 "The Obama family and Biden family greet Pope Francis as he arrives in the United States for the first time at Joint Base Andrews," Sept. 22, 2015. Peter Souza Barack Obama's best moments in the White House Feb. 21, 2014 President Barack Obama and Vice President Joe Biden participate in a "Let's Move!" video taping on the Colonnade of the White House, Feb. 21, 2014 Peter Souza Barack Obama's best moments in the White House Feb. 18, 2016 President Barack Obama watches First Lady Michelle Obama dance with 106-Year-Old Virginia McLaurin in the Blue Room of the White House prior to a reception celebrating African American History Month, Feb. 18, 2016 Peter Souza Barack Obama's best moments in the White House Jan. 21, 2013 "The President and First Lady wave to supporters as they ride in the inaugural parade. I had asked the President if I could ride in the presidential limousine and the President joked, 'But Michelle and I were planning to make out," Jan. 21, 2013. Peter Souza Barack Obama's best moments in the White House Barack Obama and former First Lady Michelle Obama share a private moment in a freight elevator at an Inaugural Ball, January 2009 all pics: Pete Souza Barack Obama's best moments in the White House Barack Obama rests his hand on the bible that President Lincoln used for his swear-in, being held by his wife Michelle Obama as he is sworn in as the 44th President of the United States of America Rex

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

Former vice-president Joe Biden will also join the campaign trail for Mr Northam.

However, his opponent Mr Gillespie has also received high profile endorsements.

Last week, Mr Trump endorsed him in a tweet, accusing Mr Northam of "fighting for the violent MS-13 killer gangs & sanctuary cities."

Mr Gillespie is also close to Vice President Mike Pence, who is set to campaign with him on Saturday.

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