Hamburg residents rejected the German port city's bid to host the 2024 Olympics in a public referendum on Sunday.
Opponents to the bid won with 51.6 percent of the vote, with 48.4 percent in favor.
"That's a decision that we didn't want, but it's clear," said Hamburg mayor Olaf Scholz.
Defeat came despite 65.6 percent of residents in the nearby city of Kiel voting in favor of the games. Sailing events had been planned for Kiel.
More than 40 percent of those eligible to vote in the referendum did so through a postal ballot more than four weeks before Sunday's vote. Around 650,000 — or half — of the eligible 1.3 million voters in Hamburg had their say.
"The result is a bitter pill for us to swallow, but a democratic decision must simply be accepted," said Nikolas Hill, chief executive of the bid committee. "We have always said that the candidacy can only be successful if it is really desired and supported by the citizens."
The result leaves Paris, Rome, Los Angeles and Budapest, Hungary as the sole bidders for the 2024 Games. The International Olympic Committee will select the host city in September 2017.
IOC president Thomas Bach had been happy to have five candidates and Sunday's result will be seen as a blow to the German.
Germany has not staged an Olympics since the 1972 Summer Games in Munich.
"I'm disappointed and sad. It would have been a big opportunity," said Dietmar Beiersdorfer, chairman of football club Hamburger SV. "It would have been a wonderful story."
Munich's bid for the 2022 Winter Games was also rejected in a referendum.
"It looks like thoughts of Olympia and Germany don't go together," said Alfons Hoermann, president of the German Olympic Sports Confederation (DOSB).
Hamburg's campaign to host the games was carried out "with lots of love and engagement," Hoermann said, and "without mistakes."
Leaders of the bid had been confident of public backing with a poll taken in March showing 64 percent were in favor of hosting the games.
But public support appeared to be worn down by several high-profile issues, including the refugee crisis; the Paris attacks; a football friendly involving Germany canceled due to a terror scare; scandals at the German football federation and FIFA; and the recent Russian doping scandal. Local activists also argued that the games would drive rents up, and the issue of funding was still not settled before the vote took place.
"We noticed a change of mood in the city," Florian Kasiske of the opposing NOlympia group said. "People can see that there are things where the money is better spent."
Organizers calculated the cost of hosting the games in Hamburg and Kiel at 11.2 billion euros ($11.9 billion). The Hamburg senate wanted the government to contribute 6.2 billion euros ($6.6 billion) while the city contributed 1.2 billion euros ($1.3 billion). Revenues of 3.8 billion euros ($4 billion) were expected to make up the rest.
"The result was heavily influenced by the conditions," Hoermann said.
The IOC said in an emailed statement that it wasn't surprised by the decision, having followed discussions in Germany in recent weeks. It said that Hamburg, Germany and sport in the country had missed out on a "great opportunity," including an IOC investment of $1.7 billion, "which compares to the 1.2 billion euros ($1.3 billion) Hamburg wanted to invest."
"It is understandable that the citizens of Hamburg are very sensitive with regard to the not yet finalized financing plan of the candidature. Even more so in a situation in which Germany has to manage a historic challenge with a high number of refugees coming into the country," the IOC said. "Therefore the high number of yes votes ... is very valuable and supports the position of (the) DOSB about the importance of Olympic Games."