Copa Libertadores champions Estudiantes took the lead when Boselli found space between Carles Puyol and Eric Abidal to guide a header past Victor Valdes.
Barca missed a number of chances throughout the second half with Ibrahimovic firing just wide of the far post after creating a shooting chance on the left of the area, and then Pedro spurned a gilt-edged opportunity.
The latter though turned from villain to hero with a last-gasp equaliser.
Centre-back Gerard Pique headed on a Xavi deflected pass into the path of the unmarked forward and his looping header found the back of the net.
The Spanish side made all the running in extra time and it was no surprise when Messi struck, diving in to chest home from a Xavi cross.
It was fitting that the Argentine Ballon d'Or winner should decide the match in his side's favour, as he is favourite to be named World Player of the Year on Monday.
This page is best viewed in an up-to-date web browser with style sheets (CSS) enabled. While you will be able to view the content of this page in your current browser, you will not be able to get the full visual experience. Please consider upgrading your browser software or enabling style sheets (CSS) if you are able to do so.