Bologna had scored twice in the last 10 minutes of normal time to stun a sparse San Siro crowd in the quarter-final tie after Fredy Guarin and Rodrigo Palacio had put Inter in control with long-range goals.
Colombia midfielder Guarin waltzed past a defender before rifling in an unstoppable shot from the end of the penalty area in the 34th minute.
Argentine forward Palacio appeared to have made the game safe in the 77th minute when he collected the ball just inside the Bologna half, ran forward, cut inside a defender and scored with a curling 30-metre shot.
Bologna suddenly came to life as Alessandro Diamanti pulled one back with a free-kick in the 80th minute and Manolo Gabbiandini equalised four minutes later, volleying in Marco Motta's cross.
Both teams could have won the game, with Javier Zanetti hitting the post for Inter and Bologna having several chances on the break, before Ranocchia headed in from a corner at the end of extra-time to earn Inter a semi-final against AS Roma or Fiorentina.
"That's the great thing about football, they could have win it as well but it went our way," said Inter coach Andrea Stramacionni. "We showed tremendous character."
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.