Kudret Idrizi's contact with the girl came to light on June 15, 2015 when her mother looked at her mobile phone and saw messages exchanged between the pair through the WhatsApp messenger service.
The "highly sexualised" messages sent from 'Dan' over the course of several hours that day included repeated requests for indecent images, which the girl refused.
Leeds Crown Court heard Idirizi, a 32-year-old Albanian national, had been 29 years old when he first started talking to the schoolgirl via the Jaumo dating app.
The girl later told police that a friend had set up a dating profile on the app for her, which stated that she was 19.
Idrizi, of Nowell Parade, Harehills, had sent indecent images of himself to the girl and suggested meeting up in Leeds while he still believed she was an adult, but ceased contact when he found out her real age.
However, the pair began talking again via WhatsApp on the day of the offence and Idrizi knew the girl was only 12 when he asked for the pictures to be sent.
The court heard it had taken considerable investigation on the part of police to trace Idrizi after the IP address used that day was found to belong to an innocent third party.
Officers raided that person's home only to discover Idirizi had been using their wifi while carrying out building work there.
He was eventually arrested last year and went on to admit one charge of inciting a child to engage in sexual activity.
Kara Frith, mitigating, said it was the girl who had resumed contact with Idrizi on June 15 and he initially told her it was wrong, before making sexual suggestions and asking for the pictures.
She said: "Clearly what he did is disgusting, but it would appear to be a moment of madness."
Ms Frith said Idirizi had no previous convictions, police found no evidence of any other inappropriate messages to underage girls, and there was a low risk of him reoffending.
She said he felt deep remorse and had become clinically depressed as a result of the shame and regret he felt.
Jailing Idrizi, Recorder Paul Greaney QC said: "It is impossible to ignore the fact that when you engaged in that highly sexualised conversation, you knew full well what you were doing was wrong."
He also ordered that Idrizi sign the sex offenders' register for life and be made subject to an indefinite sexual harm prevention order.