In the early hours of January 17th, Andreas Persson filled a fuel can at a petrol station in Borås and used it to start a fire at the town's mosque, the court heard.
Firefighters swiftly put out the blaze but the mosque suffered enough damage to require repairs which will last until summer, the local Muslim association said.
Persson, 31, was identified by video surveillance footage at the petrol service station and through mobile phone traces.
The subsequent enquiry revealed that Persson had “professed xenophobic opinions”, several months before the attack, and was already known to the authorities for drug offences and theft.
Persson denied any criminal intent, telling the court that he had wished to enter the mosque to get warm and to 'sniff” the petrol, which he then spilled accidentally. The fire started when he used a cigarette lighter to see what he had done, he said.
The prosecutor had sought a seven-year jail term.
Persson's sentencing comes amid growing concerns that refugee accommodation being targeted by far right supporters following record migration to Sweden.
Last year police investigated more than two dozen suspected arson attacks on migrant housing.
The Nordic country took in some 163,000 asylum seekers in 2015, with 10,000 a week turning up on Swedish soil during the autumn. Numbers have since dropped after the country introduced tougher residency rules and photo ID checks for all travellers arriving in Sweden.