Leeds Crown Court heard the youngsters took a photograph of 30-year-old Samuel Frost, which helped British Transport Police identify him.
Frost, 30, followed the girls aged 12 and 13 through the subway to platform one at Kirkgate rail station at around 11.30am on Sunday May 18.
Frost, of Talbot Road, Normanton, exposed himself in front of the girls and performed a solo sex act.
Frost, who had admitted engaging in sexual activity in the presence of a child, was jailed for 32 months.
After the court hearing, Sgt Jackie Wilson said: “Frost was already the subject of a lifetime Sexual Offences Prevention Order at the time of the offence.
“Both girls showed extreme bravery and managed to take a photo of Frost. It was their quick thinking actions during what must have been an extremely frightening and distressing situation that helped us identify Frost and bring him to justice.”
“This was repulsive behaviour by a sex offender who sought out the girls at the station for his own gratification.”