The Bosnian hosts were favourites to progress after a scoreless draw in Macedonia in the first leg and they looked on track as they took a 2-0 lead early in the second half.
Marjan Radeski popped up to give the visitors hope just after the hour-mark and captain Mile Krstev struck in additional time to see his side through on away goals in Sarajevo.
It was a heartbreaking finish for Zeljeznicar, who had made a promising start when Metalurg Skopje defender Ninoslav Dodevski headed a set-piece past his own goalkeeper in the 16th minute.
When Rijad Bajic struck a second from the edge of the area just nine minutes after the break, Admir Adzem's men looked set to advance.
Radeski gave his side a glimmer of hope when he cut in from the left and fired into the top corner in the 62nd minute.
Krstev delivered when coach Srgjan Zaharievski needed him most with a last-gasp equaliser sending the away side through.
Thank you for reading 5 articles this month* Join now for unlimited access
Enjoy your first month for just £1 / $1 / €1
*Read 5 free articles per month without a subscription
Join now for unlimited access
Try first month for just £1 / $1 / €1
Get the best features, fun and footballing frolics straight to your inbox every week.
Thank you for signing up to Four Four Two. You will receive a verification email shortly.
There was a problem. Please refresh the page and try again.