The 20-year-old is the first player to leave Ibrox since Mark Warburton took charge two months ago.
Gallagher scored on his Rangers debut against Dunfermline in March 2014 and scored three times last pre-season.
He only made six appearances for the club, however, and spent the first half of last term on loan at Cowdenbeath, where he scored five goals in 10 games.
The Rangers youth product could make his debut against his old side when Ian Murray takes relegated St Mirren to Glasgow in their league opener on Friday night.
Gallagher, who has also spent time on loan at Alloa and East Stirlingshire, told St Mirren’s website: “I’m really excited to get started.
“I know it’s a big season for the club having dropped down a level and the main aim has to be to get us back up there as quick as we can.”
Manager Murray said: “He’s a player we looked at a while back, being on loan at Cowdenbeath last season.
“He’s quick, he’s very direct, he likes to play on the shoulder and there’s no doubts he’s got the technical attributes to do quite well.
“We just need to make sure he’s ready and not shove him into the step up that he’s going to have to go and handle.”
Meanwhile, former St Mirren player Stephen McGinn, who spent last season at Scottish Premiership side Dundee, has signed for English League Two outfit Wycombe Wanderers on a two-year deal.