Apart from the 123 legislators of his Socialist party, just one other deputy from a regional grouping voted for Sanchez, leaving him far short of the simple majority he needed.
Some 170 members voted against, while 52 abstained.
After weeks of acrimonious negotiations, Sanchez failed to win the support of the far-left Unidas Podemos, raising the possibility of a fresh election – the country’s fourth in as many years.
Spain’s two-party system has become deeply fragmented in recent years, resulting in minority governments unable to pass major reforms without support from other parties.
Sanchez was forced to call early elections in February when his draft budget was rejected. While the Socialists won the most seats in the April vote, they fell short of a majority.
The party now has until late September to attempt further confirmation votes in Parliament. However, the it said this month it would give up trying to install Sanchez if he failed to secure confirmation in July.
“I am very sorry to note that parliament remains blocked,” the socialist prime minister told Parliament on Wednesday. “A deal wasn’t possible.”
“I want to be Spain’s prime minister, but not at any price,” he added.
The confidence vote follows months of tense negotiations between the Socialists and Podemos.
The talks became deadlocked over the question of what role Podemos would play in a coalition government, which would be the first since Spain’s return to democracy in the late 1970s.
On Wednesday, the Socialists offered Podemos the vice presidency and three ministries. However, Podemos demanded the Labour Ministry to invest in a new government – which was excluded from the Socialists’ proposal.
Podemos and the Socialists have accused each other of blocking negotiations as distrust between both sides rides high.
Sanchez strongly criticised the way Podemos and its leader Pablo Iglesias had conducted the talks, but did not say what his next step would be.
If he does not seek other confirmation votes or is unsuccessful in them, a new election will be held on November 10.
An ongoing separatist movement in the northeastern region of Catalonia, high unemployment, low wages and job insecurity will be among the main challenges facing Spain’s next government.