A groan went up in the old city of Istanbul where hundreds of hopeful Turks heard the announcement that Tokyo had been chosen to host the 2020 Olympics.
Istanbul's failed bid was a blow to Turkish Prime Minister Recep Tayyip Erdogan, who had flown straight from the Group of 20 summit in St Peters burg, Russia, to Buenos Aires to make the case.
Turkey, an early favourite, seemed to falter in June when the Government clashed violently with protesters. Istanbul's bid may also have been hurt by a string of doping scandals among Turkish athletes and the uncertainty of neighbouring Syria's civil war.
The city was prepared to celebrate. Large TV screens were put up in front of the sixth-century former church of Hagia Sophia. Music blared and red-and-white Turkish flags waved.
The crowd was ecstatic when just over an hour before the final announcement they watched the IOC declare that Istanbul had beaten Madrid to reach a final round of voting against Tokyo.
But when the final announcement was made after 11pm in Istanbul, a brief sound of disappointment gave way to silence and the crowd quickly dissipated. Tokyo had defeated Istanbul 60-36 in the final round of secret voting.
Erdogan had argued that a successful Olympic bid for Istanbul would make it a first for a predominantly Muslim country in a city linking the continents of Europe and Asia. After the vote, he expressed disappointment. "It wasn't our fate," he said, according to Turkish news reports.
The disappointment comes at a politically sensitive time for Erdogan as he faces a series of elections. The Turkish economy is looking increasingly shaky after a decade of growth and the protests have polarised the country. The Olympic bid had already become a political issue well before the disappointment.
Turkey's minister in charge of ties with the European Union, Egemen Bagis, caused a storm last month when he suggested that anti-government protesters would be to blame if Istanbul lost the bid.
It was a charge the country's main opposition party said was an attempt to "camouflage" any possible failure.
The choice of Tokyo was received like a cold shower in Madrid, where hopes had been high that the Spanish capital would win its third consecutive Olympic bid. "A dream has fled from us," Deputy Prime Minister Soraya Saenz de Santamaria wrote on Twitter after Madrid was eliminated in the first round of a ballot by the IOC.
Socialist opposition leader Alfredo Perez Rubalcaba said he was "very sorry".
"Madrid had worked hard and well" to get the Olympics, he wrote on Twitter.
Thousands of people had gathered in the city centre, where they waved red balloons while being entertained by musicians.
When the news broke that Madrid had been ousted from the race, some people broke into tears. "This is unfair. It is a fraud," one man said, slamming the IOC as a "mafia".
It was Madrid's third consecutive bid to host the summer Olympics, after it lost to London in 2012 and Rio de Janeiro in 2016.
"Not even in its worst dreams would Madrid have expected to be eliminated already in the first round of voting," the daily El Mundo said.
The choice of Madrid to host the Olympics would have lifted spirits in a Spain hit by a six-year economic slump, where more than a quarter of the workforce is unemployed, many analysts said.
"Now at a time of crisis, it would have suited us very well to celebrate the Olympics in Spain for improvements for the country, for the jobs that would have been created, to make sports more popular," national water polo representative Lorena Miranda said.
Others said that accepting a defeat was part of the spirit of sports. "To make it until the last day and to lose is tough, but Madrid needs to feel proud. It did a magnificent job," said Eduardo Portela, president of the Spanish Association of Basketball Clubs.