OTTAWA (Reuters) - The struggling leader of Canada’s left-leaning New Democrats, an opposition party that competes with the Liberals of Prime Minister Justin Trudeau, on Monday won a parliamentary seat and secured his immediate political future.

Slideshow ( 9 images )

Preliminary results showed Jagmeet Singh won a special election to fill an empty seat in the parliamentary constituency of Burnaby-South, in the Pacific province of British Columbia.

Singh captured just under 40 percent of the vote.

A practicing Sikh, Singh made headlines in October 2017 when he became the first person from an ethnic minority to be elected leader of a major Canadian political party. But he has failed to lift the New Democratic Party (NDP), which trails its rivals badly.

The NDP and the Liberals - who compete for the same center-left segment of the electorate - will face each other in a federal election this October. The worse the New Democrats do, the better Trudeau’s chances become.

“This staves off all the talk that Singh would have to quit ... at least for the moment he is vindicated,” said Richard Johnston, a political science professor at the University of British Columbia.

Johnston said in a phone interview that Singh would still need to overcome unhappiness with his leadership.

Singh, 40, a former legislator in the province of Ontario, had no experience in federal politics when he took over from former leader Thomas Mulcair.

He has clashed openly with senior members of parliament on a number of issues. A quarter of the 44 NDP legislators who won seats in the 2015 election have either already quit or announced they are not running again in October.

And in a further sign of challenges ahead, in another special election on Monday, the NDP lost the Montreal seat Mulcair had held to the Liberals.

An Ipsos-Reid poll for Global News last week put the Liberals at 34 percent public support and the right-leaning official opposition Conservatives at 35 percent. The NDP was far behind at 17 percent.

The Liberals are stumbling amid allegations that officials in Trudeau’s office leaned on former justice minister Jody Wilson-Raybould last year to help a major construction company avoid a criminal trial on bribery charges.

Singh and Conservative leader Andrew Scheer are both calling for a public inquiry into the matter.