Initially predicted to pick up 4.8 percent of Sunday's vote in the city state, the final count put AfD at 5.3 percent, just above the five-percent minimum required to enter parliament under German electoral law.
The anti-immigrant party nonetheless suffered losses compared to the last state elections in 2015, when they picked up 6.1 percent of the vote.
Largely unpopular in the cosmopolitan port city, the AfD struggled further in the wake of a racist attack which killed nine in central German city Hanau last week.
“Getting in by a whisker is a huge success in this case because we were subjected to campaigns from the entire political establishment of the city of Hamburg,” said regional AfD leader Dirk Nockemann.
The liberal FDP party, meanwhile, also appeared to edge over the five-percent hurdle to retain its place in Hamburg's parliament.
This graphic shows, in percentage, which parts of Hamburg voted the lowest and highest for the AfD. Graph: DPA
Final estimates put the FDP on five percent exactly, although with some constituencies yet to finalize their counts, their fate remained in the balance on Monday morning.
The liberal party was hit hard by a recent scandal in the eastern state of Thuringia where their candidate was elected state premier with the help of votes from the AfD.
“After the latest projections, it's likely that AfD will stay [in parliament] and that the FDP muss continue to be worried.”
Nach der jüngsten Hochrechnung (Stand 22:45 Uhr) wird ein Verbleib der AfD in der Bürgerschaft wahrscheinlicher, die FDP muss weiter bangen. #HamburgWahl https://t.co/rVNV0bbjlh pic.twitter.com/5wKExoDBT2
— tagesschau (@tagesschau) February 23, 2020
The move broke a taboo on cooperation with the far right and unleashed a national scandal which also plunged Angela Merkel's ruling CDU party into crisis.
The centre-right party also suffered embarrassment at the Hamburg polls, slipping to just 11.2 percent of the vote, a showing nearly five percentage points worse than in 2015.