The winner faces a tough fight to keep the Socialist Party in power after steep declines in popularity for current leader President Francoise Hollande.
Hollande announced he wouldn't stand for a second term last year, leaving the winner of the leadership ballot to take on the Republican Party's Francois Fillon and Marine Le Pen, of the far-right Front National, for the Presidency in April.
With half of the votes counted, Hamon, who wants to tax robots, create a universal basic income and recognize "burn out" as a professional ailment, was ahead with 36% of the vote.
Valls followed with around 31%. Former Economy Minister Arnaud Montebourg abandoned the race after coming in third place and urged his supporters to back Hamon.
Hamon, an admirer of US Senator Bernie Sanders, stepped into the political spotlight as part of Francois Hollande's cabinet in 2014 and again in August 2016 to launch his presidential bid.
He's perceived as a rebellious leftist outsider who wasn't considered a serious political contender when the presidential campaign kicked off in December 2016.
Following the results, Hamon tweeted
that he would continue to defend the priority given to social issues, the environment and democratic renewal.
Valls, well-known among French voters after serving as Prime Minister from 2014 to 2016, invited his followers to show up next Sunday and vote to make him the official nominee of the Socialist Party.
Valls is known as a Hollande loyalist and is known for being a reformist positioned on the Socialist Party's right. He stood as a candidate in 2012, but was defeated by Hollande.
It was the first time since 1958, when France's fifth republic was created, that an incumbent president had not sought re-election.
While the competition between Hamon and Valls will focus the attention of the Socialist electorate, it's considered unlikely the party will emerge victorious in the final event.
After five years under Hollande, and in the wake of terrorist attacks and an influx of refugees fleeing unrest in the Middle East, the French electorate is showing signs of shifting to the right.
Fillon's hardline stance on Islamic terrorism and his desire to increase France's security and defense budget, saw him win the Republican Party's first-ever US-style primary run-off in November 2016, beating Bordeaux Mayor Alain Juppe by securing 66 % of the votes
France's Front National has also grown in popularity.
With leader its leader Marine Le Pen spearheading a campaign to "detoxify" the party founded by her father Jean-Marie of its reputation for racism and xenophobia, the party saw its share of the vote rise to 27% in last year's regional elections.
Under such circumstances, the France's Socialist Party -- currently divided between left-wing radicals and pro-market reformists -- require a more united front if they wish to pull themselves up from their current fifth place in the polls.