"Part of my political life is coming to an end. I am leaving the Socialist Party, or the Socialist Party is leaving me," the 54-year-old told RTL radio.
Valls, who was prime minister under Socialist president Francois Hollande from 2014 to 2016, was rejected by Socialist voters in the party's primary to choose a candidate for this year's presidential election.
The party chose hard-left candidate Benoit Hamon instead and he failed to reach the run-off of the presidential election in May as France's two main parties fell at the first hurdle for the first time since 1958.
Macron's Republic on the Move (REM) party won a commanding majority in the legislative elections that followed.
The Socialists were humiliated and won just 30 seats as voters punished the party for five years in power overshadowed by sluggish economic growth and high unemployment.
Valls had approached REM about running as a candidate in the legislative elections but in the end an arrangement was reached under which REM did not field a candidate against him.
Government spokesman Christophe Castaner said Valls's decision "is not a surprise".
A parliamentary source said that while Valls would not be an REM lawmaker in the National Assembly, he would have a status allowing him to enjoy the advantages that would bring, such as speaking time in debates.
The pugnacious, Spanish-born Valls was Macron's boss when the now-president was economy minister and a fierce rivalry developed between them.