Council property occupants in Edinburgh have voted narrowly not to allow housing associations to take over control of their homes.
The "no" campaign in Edinburgh has won the day
In a ballot, 53% of the capital's council residents who voted opposed the transfer following a "no" campaign.
Critics were jubilant at the outcome but the council leader, Donald Anderson, warned rents may rise.
Meanwhile, tenants in Argyll and Bute have voted nine to one in favour of the transfer.
A "yes" vote in Edinburgh would have meant the Treasury writing off millions of pounds of housing debt.
Edinburgh's debt currently stands at about £300m and almost half the rent received by the local authority goes towards paying it off.
The council had described the ballot as a "once in a lifetime opportunity" for tenants and said a "yes" vote would have meant the delivery of 10,000 new affordable homes over the next 10 years.
But the city's council tenants voted by 7,301 to 6,553 against the planned transfer.
The 53%-47% defeat came in a postal ballot with a 60% turnout. Tenants from approximately 23,000 homes were eligible to take part.
Mr Anderson described the outcome as "an enormous setback". He said rent may have to go up rent increases and it would be almost impossible to find the money needed to build new homes.
The council said all options would be explored to find solutions to the city's housing problems.
Housing spokeswoman Sheila Gilmore said: "In particular, there will be a request to the Scottish Executive for help to provide the extra affordable housing which the city badly needs."
A spokeswoman for the Scottish Executive said: "We are disappointed at the result.
"It will now be for Edinburgh City Council to look at the way forward, and the executive will provide whatever support is possible"
Despite the council's predictions that a positive result would lead to lower rents, opponents were concerned that the switch away from local authority control would amount to privatisation and lead to a loss of democratic control over social housing.
Local campaign group Edinburgh Against Stock Transfer (EAST) said it was pleased with the result of the vote.
Johnny Gailey, a tenant from the Dumbiedykes area and EAST member, said: "Finally, after all the council's hot air, the tenants have had their say.
The council said the vote was a "once in a lifetime" opportunity
"I am pleased that the tenants of Edinburgh have seen through the council's plans to abandon their tenants and privatise their homes.
"I trust the council will now represent their tenants' wishes and work on their behalf to pressurise the central government to release the money which was there on the table as a sweetener for the private sector.
"If the money was there for a private organisation, it should now be there for the council too."
Gavin Corbett, head of campaigns at Shelter Scotland, said Edinburgh and other Scottish councils faced major housing challenges.
"For months now the council has pinned many of its plans on transfer going ahead and it now faces a major rethink as a result of tenants voting no," he went on.
"The city faces a major shortfall in affordable housing and the transfer included proposals to build 10,000 new affordable homes.
"It is essential that these plans are not lost, for the sake of tenants of tomorrow.
"When the dust settles we urge local and national politicians to get round the table to discuss how the city can meet the urgent housing challenge that it still faces."
The Scottish National Party called on the executive to ensure that Treasury money earmarked for housing improvement in the capital would still be put towards that purpose.
The party's housing spokeswoman Tricia Marwick said: "It is clear that Edinburgh City Council has failed to win the debate on its stock transfer plan and the will of the tenants must now be respected."
Scottish Socialist Party national convenor and Lothians MSP Colin Fox paid respect to the "magnificent" campaign against Edinburgh's council house stock transfer.
He said: "The billion pounds that was dangled as a carrot in front of the city's tenants must now be spent on badly needed public housing in Edinburgh."
The Conservative housing spokeswoman Mary Scanlon MSP said: "I hope the Scottish Executive will now hold discussions with Edinburgh City Council over the future of housing stock, with a view to assisting in future investment for vital affordable housing."
"Regardless of this result, the executive must now press the Treasury to ensure that the money is channelled into much-needed improvements in the standard of Edinburgh's council housing stock."
The Convention of Scottish Local Authorities (Cosla), which represents Scotland's local authorities, said the democratic decision sent a "clear message" to ministers that they must rethink their policy on stock transfer and strategic housing investment.
"Councils that continue to undertake the landlord role should have the same investment opportunities as transfer authorities," Cosla's housing spokesman Councillor Douglas Reid said.
"Can anyone really argue that Edinburgh's housing stock is any less in need of investment now that tenants have voted against stock transfer?"
- In Argyll and Bute, the outcome of the ballot was 89.6% in favour, which is said to be a UK record high for any large-scale housing transfer.
Council officials said the result - 3,584 of tenants in favour to 415 against - meant an investment of more than £260m would be available to the Argyll Community Housing Association to spend on improving homes and services.