The winger stole in ahead of goalkeeper John Sullivan to net his second goal of the match in the 92nd minute.
Portsmouth had taken the lead through Patrick Agyemang in the fifth minute. He capitalised on Steve Elliott's stumble to poke the ball past goalkeeper Scott Brown from close range.
Agyemang should have been celebrating again in the 13th minute when he blazed over with the goal at his mercy after a fine run from Yassin Moutaouakil.
Portsmouth held the upper hand for most of the half, but the introduction of Russ Penn from the bench injected life into Cheltenham.
He replaced the injured Ryan Inniss and soon after a reshuffle, Terry Gornell set up McGlashan for the equaliser in the 36th minute.
The quick winger rounded Sullivan and applied a neat finish inside the bottom corner.
Cheltenham pressed for a second, enjoying their best period of the half, but Portsmouth regained the lead in the 43rd minute.
Jed Wallace reached the byline and pulled back for Ertl to tap into an empty net and it looked to be enough until McGlashan struck at the death.