A Canadian man says he has been told to leave Nepal after he was detained by police in Kathmandu on Monday for posting tweets that Nepal's Department of Immigration said had caused "social discord."

Robert Penner, a software engineer for a tech company in Nepal, tweeted on Tuesday that he was released by immigration officials after 26 hours in custody. Penner said he had his visa cancelled and was given two days to leave the country after he was found to be in violation of the terms of his visa by the Department of Immigration.

Nepal Immigration released me after 26 hrs in custody, cancelled my working visa & gave me 2 days to leave Nepal. Thanks to all supporters. —@robpenner

On Monday, Penner posted several tweets commenting on his arrest, and the arrest and trial of Nepalese journalist Kanak Dixit, who faces corruption charges. Penner frequently writes and comments on Nepalese politics.

"Police were watching his [Penner's] activities for a long period," Basu Dev Ghimire, director of Nepal's Department of Immigration, said Tuesday. "Police found him guilty."

Nepal police came to my office. They're taking me to Jawalakhel. —@robpenner

I repeatedly asked Nepal Police to tell me under what charges they're taking me but they won't say. —@robpenner

The police reported his political commentary to the Immigration Department, which then ordered his arrest on Monday evening.

Penner was detained overnight in the Immigration Department's headquarters, where he was held in an office by police. On Tuesday afternoon, he was still detained at the immigration office, but his lawyer expected him to be released by Tuesday evening.

"They've taken my phone and not allowed me to contact people," Penner said in the afternoon before police escorted this reporter out of the office where he was being held.

According to immigration officials, the political commentating is a violation of the provisions of his work visa. A Nepalese work visa can be rescinded from someone if he or she is found to have caused public unrest. Department of Immigration Director General Kedar Neupane said Penner's tweets caused "social discord."

Immigration officials claimed they were not violating free speech, but had received complaints about Penner.

Penner has lived in Nepal since 2012, working for tech startup Sprout Technology Pvt. Ltd., which is a subsidiary of Hong-Kong based CloudFactory. The company has over 150 employees, a handful of which are expats on work visas. According to his LinkedIn profile, Penner graduated from Trinity Western University in British Columbia in 1999.

CloudFactory CEO, Mark Sears said via email that CloudFactory did not have any comment, but went on to say, "Robert is a valued engineer and employee whom we care deeply about but he has made it clear that any statements or opinions expressed in public forums are solely his own and in no way reflect those of CloudFactory or its leadership."

Nepal's Prime Minister Khadga Prasad Sharma Oli, seen here at an event to initiate the reconstruction at Swoyambhunath Stupa, a UNESCO world heritage site, a year after the 2015 earthquakes in Kathmandu, on April 25. Some Nepalese journalists see Penner's arrest as a warning against them. (Navesh Chitrakar/Reuters)

Penner known to talk politics

Penner has taken an in-depth view into Nepalese politics on Twitter and blogging sites, and even travelled to the southern part of Nepal, where ethnic groups were protesting the recently passed Constitution.

He was also involved in a Twitter and blog feud over a Human Rights Watch report that came out in October last year. The report criticized the Nepalese police for brutality against people protesting the new constitution.

It's an intimidation of the people who are trying to bring the reality of the Nepalese people to the rest of the world. He's not here to destroy Nepal. His criticism is actually constructive. - Mukesh Jha, Nepalese blogger

But some Nepalese resent foreigners becoming involved with or commenting on internal politics, and one Twitter user complained of Penner's commentary to the Immigration Department's Twitter account on Monday. Although officials said that the Twitter complaint did not incite the arrest and that it was a result of police monitoring, some believe there are larger powers at play in the investigation.

"It's an intimidation of the people who are trying to bring the reality of the Nepalese people to the rest of the world," said blogger Mukesh Jha, founder of Madhesiyouth.com, which is linked to the ethnic group protesting the Constitution. "He's not here to destroy Nepal. His criticism is actually constructive."

Jha suggested that Penner may have offended some higher-ups in Nepalese society, who then moved to have him arrested.

For some Nepalese bloggers and journalists, his arrest is seen as a warning. Many believe the government is flexing its muscles, sending a message that prominent journalists like Kanak Dixit and foreigners like Penner are not out of their reach.

On Tuesday, Twitter buzzed with invocations to stand up to the government.

"Who's next? That's the question," Jha asked.