"We are going to protect the weakest, unify Spain and express a clear voice in Europe," Sánchez told party members after being chosen with 49 percent of the vote.
Basque lawmaker Eduardo Madina — the early front runner — scored some 36 percent and former MP José Antonio Pérez Tapias garnered a little over 15 percent, the party said after counting four-fifths of the ballots from the direct election by the party's nearly 200,000 members.
Sánchez, 42, has cultivated a down-to-earth image in his late bid to turn around the Socialist Party's flagging fortunes ahead of elections in 2015.
"I am a rank-and-file activist. A year and a half ago I was not a politician," he said at a party debate ahead of Sunday's vote.
"My only equipment is my Peugeot 407, in which I have driven 40,000 kilometres (25,000 miles) in the past eight months, and my allies are the road and party activists."
An economist nicknamed El Guapo or "The Handsome One" has cast himself as a fresh face for the PSOE party.
The Socialists were turfed out of seven years in power in a crushing November 2011 election defeat, seen as punishment for a recession, mushrooming debt and sky-high joblessness.
Their loss of support in May's European elections prompted the resignation of their outgoing leader Alfredo Pérez Rubalcaba, 62.
In campaigning, Sánchez fought to fend off the challenge from Podemos, a new leftist protest party that did well in the European polls.
Sánchez may have been relatively unknown until now in Spanish politics, but his clout and experience are more considerable than his humble act may suggest.
He has a master's degree in politics and economics from a Belgian university. He served as a top aide to the head of a UN high representative during the war in Kosovo.
He has since served on and off as a non-elected regional deputy in Madrid.
The choice of Sánchez must now be validated by an extraordinary Congress of party delegates, to be held July 26th-27th in Madrid.
Complicating matters further, the Socialist Party's candidate for prime minister in the 2015 elections will be chosen by a separate, direct poll of party members in November.