A pro-democracy candidate has won a crucial by-election in Hong Kong weeks after riots over apparent crackdown on street vendors exposed simmering ant-China tensions in the self-ruled city.

Holden Chow of the Pro-Beijing Democratic Alliance for the Betterment of Hong Kong was defeated by more than 10,000 votes by Alvin Yeung of the pro-democracy Civic Party.

Edward Leung Tin-kei, who was arrested following the street riots, secured the third place.

The 24-year-old indigenous leader had exhorted the residents last month to use "any means necessary" to fight against what he called the "re-colonialisation" of the city by China.

The student leader got 66,524 votes while the winning candidate Yeung won 160,880 votes.

The election was held after the seat became vacant following the resignation of a prominent pro-democracy leader.

The street violence was reminiscent of the pro-democracy protests in late 2014. It was triggered when police cleared hawkers who peddled local delicacies from street-side stalls.

More than a hundred protesters broke loose in Portland Street at 2 am, forcing police to engage them.

The street protests, which received instant social media backing, also spread to areas surrounding Shantung and Soy Streets.

Riot police clashed with protesters and fired two warning shots as protesters launched missiles and set fires in the working-class district of Mong Kok.

Hong Kong's Chief Executive CY Leung said the rioters were "seriously jeopardizing the safety of police officers and other people at the site."