3d Print pops off before complete
The issue you are having is with bed adhesion.  Basically your print is not sticking well enough to the printer bed for it to resist the mechanical forces the part is being subject to during print.

This the most common issue in FDM 3D printing and you can find a lot of material online on how to mitigate the problem.  Just as a "teaser":


You need to ensure your printing bed is dead flat and at the right distance from your nozzle.  Search online for: "3D printer bed leveling": the procedure is normally the same for most printers, but if your model is a common one, chances are you will find a video/how-to/blog post for it.
You should use print settings that facilitate bonding of the plastic to the bed (typically: slow speed, no cooling fan, a bit of overextrusion...)
You can tell the slicer to add a brim or a raft to your part, to increase the amount of material holding down the print.
You have the option to cover your printing bed with some material that increases the bonding of the plastic (this is type-of-plastic specific but typically: PVA glue or painter's tape work well for PLA, and kapton tape or ABS sludge for ABS).
If you have a heated bed, use it (each filament brand has their own recommendations, but typically 50-60°C works well for PLA).


As for why your problem is happening towards the end of the print, there are a series of factors contributing to it:


The tallest the print, the more mechanical advantage (leverage) the nozzle has over the adhesion surface.
It looks like your top layers are progressively small, so they print very fast and this in turn the does not allow for the plastic to completely cool down before going to the following layer, so when the nozzle prints on top of it the still-warm layer is "pulled up" by the action of the nozzle, creates a blob that sticks to the nozzle and that only makes situation worse.  Snowball effect.  Most slicers have an option "minimum layer time" that delays the print of a layer until X seconds have passed from the start of the previous one.
It may be possible that the Z axis is inaccurate and the nozzle catches on a previous layer.  Most printer have some kind of accuracy issue with the Z axis the furthest up the head is, especially if the Z-axis has only one threaded rod (as for example in the Creality CR-10).  Another source of inaccuracy (see comments below) could be the movement multiplier for the Z being slightly off, causing the nozzle to dig into the print if there's overextrusion and enough cumulative error.  Z axis inaccuracies are however unlikely to be the primary source of troubles for you, but it's a "nice to know" thing to know about 3D FDM printers, nevertheless.