Nepal has cancelled the working visa of a Canadian citizen and ordered him to leave the country, saying his critical posts on Twitter could disturb the country’s social harmony.

Nepal’s Department of Immigration on Tuesday ordered Robert Penner—who works at a technology start up in a Kathmandu suburb– to “voluntarily leave” the country by Thursday.

His posts on the social media site Twitter have included criticism of the country’s new constitution as well as its treatment of plains-dwelling Nepalis, called Madhesis, who have been demanding greater rights.

One of his tweets from earlier this year said “fast-tracked constitution led to huge economic disaster.”

In his most recent posts on Twitter, Mr. Penner commented on the arrest of Kanak Mani Dixit, a senior Nepali journalist, by Nepal’s anti-corruption body on the allegations that he misused public money as the head of a transport cooperative in Kathmandu. Mr. Dixit, who denied any wrongdoing, was released Monday.

Police picked up Mr. Penner at his office on Monday and put him in custody at immigration department which wanted to interrogate him after complaints about his “political activities.”

“It seemed our communal harmony, peace and security would be disturbed if he continued to stay here,” said Kedar Neupane, director general of the immigration department. “He shouldn’t have indulged in the business of making unnecessary comments while holding a work visa.”

Mr. Neupane pointed to Nepal’s 1992 immigration law that says a foreigner’s visa can be cancelled if “his or her presence seems to cause an adverse impact on peace and security of Nepal or mutual harmony between the people of Nepal.”

The department released Mr. Penner late Tuesday after cancelling his visa and ordered him to leave the country within two days.

On Wednesday, Mr. Penner petitioned Nepal’s Supreme Court against the cancellation of his visa.

“I have only exercised my freedom of expression through Twitter,” Mr. Penner said in his appeal to the court. “I have no bad intentions.”

Mr. Penner had been working at the tech company CloudFactory’s Nepal office in Kathmandu’s suburb of Lalitpur for more than three years, according to Kabin Pandey, the company’s human resources manager.

The company employs 165 people at its many offices around the world, including in Nepal, doing online jobs like data processing, Mr. Pandey said.