Substitute Maciver cancelled out Blair Spittall's first-half header when he turned and curled a 25-yard effort into the far top corner with nine minutes left.
The Inverness-born 20-year-old was making his first appearance since moving from County to Fir Park in the summer.
And there was more drama to come as Gallagher rose highest to head home Liam Polworth's corner.
Dozens of visiting fans spilled on to the pitch to celebrate as Motherwell's victory kept them in third place in the Ladbrokes Premiership.
Motherwell had squandered a number of first-half chances before piling on the pressure after Lewis Spence was sent off for the home team in the 62nd minute.
Motherwell were without both Christopher Long and Devante Cole meaning James Scott resumed his centre-forward role, and the 19-year-old was heavily involved in an open start to the game.
Scott was twice crowded out in promising Motherwell attacks before shooting wide from the edge of the box. And he had a glorious chance in the eighth minute when Polworth played him clean through but hit Nathan Baxter with his first-time strike.
Spittal twice shot over but the visitors kept threatening. Allan Campbell was off target with a free header, Scott chipped a shot just beyond the far post and Baxter got down well to stop Polworth's long-range drive.
County netted against the run of play as they kept the pressure on after Billy McKay was inches from connecting with a header in the six-yard box. Sean Kelly hit a cross from the left which Spittal ran on to and guided a header inside the far post, with Mark Gillespie only able to help it in.
Ross Stewart sent a free header wide after a free-kick from the left had eventually found its way to the County striker before Motherwell finished the half strongly.
Jermaine Hylton turned and shot just wide from 30 yards before setting up Polworth for a golden opportunity which the midfielder hit just past with only the goalkeeper to beat.
Motherwell's early second-half efforts came from long range before Spence was sent off. The midfielder, earlier booked for pulling down Polworth in the act of shooting, slid in to upend Sherwin Seedorf as the winger raced on to Polworth's perfect through ball. Referee Greg Aitken produced a straight red card.
Baxter held Jake Carroll's low drive from the resulting free-kick.
McKay came close from 20 yards moments later before the game settled into a pattern of Motherwell attacking the 10 men.
Gallagher was twice off target, Baxter stopped with his foot after Polworth drove a free-kick through a crowd of bodies, and the keeper saved Scott's flick and Mark O'Hara's free-kick.
County substitute Brian Graham shot wide on a promising break before Maciver – who only made one substitute appearance for County – broke the home side's resistance.
Motherwell then hunted for a winner and they got it with seconds remaining thanks to Gallagher's header.