Valls, a reform-minded centrist, was beaten in the first round of the leftwing primary by dark horse Benoit Hamon.
Valls, a reform-minded centrist, was beaten in the first round of the leftwing primary by dark horse Benoit Hamon, setting up a showdown next Sunday between two factions of the Socialist party.
Valls, 54, immediately dismissed Hamon as a mere protest vote.
"A clear choice is before us -- the choice between certain defeat and possible victory," he said.
As Valls seeks to clinch the nomination of a party that is in the doldrums after five troubled years under President Francois Hollande, he knows the Socialist candidate could face a torrid time in the presidential election.
Forecasts currently show it is likely to be a showdown between rightwing candidate Francois Fillon and Marine Le Pen, leader of the far-right National Front (FN).
When Hollande said in December he would bow out after a single term beset by stubbornly high unemployment, mass demonstrations and deadly terror attacks, Spanish-born Valls quit the government to try to succeed him as president.
An already daunting task has been made even harder by the success of Emmanuel Macron, the 39-year-old former economy minister under Hollande who has created a buzz on the campaign trail.
Valls has never disguised his contempt for Macron, clashing with him repeatedly when they were in the cabinet.
Having stood as a candidate in 2012 when he was defeated by Hollande, Valls would have been hoping for better luck this time after helping to elbow aside his boss.
Born to a Spanish painter father and Swiss-Italian mother, the 54-year-old has an unusual family background for a modern French leader.
Valls makes no apologies for his pro-business stance and desire to modernise the Socialist party -- in 2007 he proposed changing the party's name which he judged old-fashioned.
He has warned "the left could die" and has described the emergence of two "irreconcilable" factions -- one pragmatic and open to reforms, the other wedded to the class struggle.
Such statements drew comparisons in the past to former British prime minister Tony Blair who dragged his party to the centre ground and won three successive elections.
But Valls' use of decrees to ram through contested economic reforms as prime minister, as well as a failed proposal to strip dual-national terrorists of their French citizenship, alienated many in the party.
Last August, he waded into the debate on the Islamic "burkini", declaring the full-body swimsuit "not compatible" with French values in a sign of his stern line on Islam in France.
"He says things with a certain honesty, a certain clearness, and yes, sometimes a certain roughness," Alain Bauer, a prominent French criminologist and friend of Valls since their student days, told AFP.
Valls' family fled the dictatorship of Francisco Franco in Spain to settle in France, but they travelled back to Barcelona for his birth in August 1962. He gained French citizenship when he was 20.
Unlike many members of the French political elite, the lifelong Barcelona football fan did not attend the prestigious ENA school of administration, studying history instead.
Valls has four children from his first marriage to a teacher. In 2010 he remarried, to Anne Gravoin, a glamorous concert violinist.
He cut his teeth working as an aide to former Socialist prime ministers Michel Rocard and Lionel Jospin.
In 2001, he became mayor of the tough high-immigration Paris suburb of Evry and was elected to the National Assembly a year later.
His experience in Evry has informed his views of France's notoriously rough suburbs, saying those who live there suffer "apartheid".