UEFA Champions League debutants PFC Ludogorets Razgrad were denied a place in the third qualifying round by Domagoj Vida's winner eight minutes into added time.
With the score level at 1-1 from the first leg in Bulgaria, Ante Čačić's men had a slight advantage heading into the return. However, a spirited attacking display from the visitors helped them twice take the lead, through Emil Gargorov and Marcelinho. Ante Rukavina cancelled out both goals, and Marcelinho was sent off, but a defiant Ludogorets looked set to progress until Vida's last-gasp intervention.
The visitors started the brighter and were rewarded when captain Gargorov headed in Ivan Stoyanov's free-kick. Dinamo struggled to impose themselves but equalised from a rare foray forward on 33 minutes. Šime Vrsaljko broke down the right and crossed for Rukavina to head in off a post.
Ludogorets continued to impress and were ahead again soon after. Marcelinho capitalised on another excellent Stoyanov set-piece to grab his second of the tie. However, the midfielder was shown a red card on 57 minutes after collecting his second booking. Buoyed by their numerical advantage, Dinamo surged forward and levelled again on the hour through Rukavina, who reacted quickest when Milan Badelj's pass deflected his way.
Despite their pressure, though, a winning goal seemed unlikely until the very last touch of the match, when Vida's terrific header from substitute Ivan Peko's right-wing cross sent the home fans into raptures. The visitors' misery was compounded when Miroslav Ivanov saw red in the aftermath of the goal. Dinamo go through to play Moldova's FC Sheriff in the next round, with the first leg next Wednesday.