“This is what happens when the people vote. Congrats Ralph Northam and Phil Murphy,” Mr Obama said in a Twitter post.
“And congratulations to all the victors in state legislative, county and mayors' races. Every office in a democracy counts!”
This is what happens when the people vote. Congrats @RalphNortham and @PhilMurphyNJ . And congratulations to all the victors in state legislative, county and mayors' races. Every office in a democracy counts!— Barack Obama (@BarackObama) November 8, 2017
In Virginia, Ralph Northam defeated Republican Ed Gillespie following an election campaign marked with clashes over immigration and Confederate statues.
Meanwhile, Democrat Phil Murphy easily beat Kim Guadagno to become New Jersey governor, with the Republican struggling against the unpopularity of Mr Trump in the state and the outgoing Republican Governor Chris Christie's historically low approval ratings.
A number of the winners in Tuesday's elections were from minority backgrounds, leading to speculation Mr Trump's presidency motivated more black and minority ethnic people to vote.
A black transgender activist, Andrea Jenkins, was elected to the Minneapolis City Council, while a Hispanic woman won the mayor’s race in Topeka, Kansas and a Sikh man was elected mayor in Hoboken, New Jersey.
Vietnamese, Latina and transgender candidates also won state legislative elections and black candidates became lieutenant governors in New Jersey and Virginia. In Helena, Montana, a Liberian refugee was elected mayor.
The results are thought to be an early bellwether of the outcome of next next year's midterm congressional elections.