It was an exceptional victory for the Bulls, considering they were playing with 14 men from the 51st minute, when centre Francois Venter made his exit due to a vicious spear tackle on George Earle, and were trailing 16-26 with just eight minutes remaining.
But wing Mastriet and flyhalf Boshoff, both of whom looked exciting with ball in hand throughout the match, both scored tries in the thrilling conclusion to ensure the defending champions don't go out just yet.
The Lions made a fine start to the game when centre Alwyn Hollenbach sped over for the opening try, but flyhalf Elton Jantjies missed the conversion. Missed kicks would be a recurring, and extremely costly, theme for the Lions with Jantjies leaving 10 points on the table.
The Bulls took the lead in the 23rd minute when prop Morne Mellett bustled over for a try, which Boshoff, who had a fine afternoon with the boot, converted.
The rest of the first-half scoring would be kicks as Lions fullback Andre Pretorius kicked two penalties and Boshoff one to leave the home side one point ahead at the break.
The Bulls were quick to regain the lead after the interval, however, with Boshoff kicking a 41st-minute penalty.
Lions Kevin Buys was shown a yellow card in the 42nd minute for using the elbow as over-enthusiastically as a kid on prom night, but Pretorius regained the lead for the Lions with a penalty and Venter followed the replacement prop on to the sideline, but permanently, for trying to plant Earle in the turf.
The Lions suddenly burst into life in the final quarter, with tries by wing Dusty Noble and scrumhalf Michael Bondesio as they streaked 26-16 ahead.
But the Bulls' Vodacom Cup adventure - they scraped into the quarterfinals after losing five games - did not end there. An exciting period of sustained pressure eventually saw Mastriet take the gap to score, with Boshoff converting to make the score 23-26.
The Bulls roared back on to attack from the kick-off, keeping the ball through phase after phase, before Boshoff eventually risked going it alone down the blindside and scored the match-winning try.
Lions replacement centre Hein Cronje tried a drop goal in injury time, but it was charged down to give the Bulls an extraordinary victory.
While Boshoff and Mastriet were outstanding for the Bulls, loose forward Jaco Kriel had an excellent game for the Lions.
Scorers
MTN Golden Lions- Tries: Alwyn Hollenbach, Dusty Noble, Michael Bondesio. Conversion: Elton Jantjies. Penalties: Andre Pretorius (3).
Vodacom Blue Bulls - Tries: Morne Mellett, Sampie Mastriet, Marnitz Boshoff. Conversions: Boshoff (2). Penalties: Boshoff (3).