HONG KONG — In quiet negotiations as well as public protests, they have pleaded and demanded for nearly two decades that Beijing allow Hong Kong’s leader to be elected by the general public. But in a dramatic vote on Thursday, pro-democracy lawmakers here rejected a bill that could have been their last best chance to achieve that goal.

In doing so, they redrew the battle lines in the struggle over Hong Kong’s future and may have ushered in a more volatile era in the city’s politics.

The measure that failed would have allowed the public to elect Hong Kong’s next chief executive in 2017 from a slate of two or three candidates nominated by a committee controlled by China’s ruling Communist Party.

But in a twist that speaks to the awkward politics of a freewheeling former British colony ruled since 1997 by an authoritarian government in Beijing — as well as a last-minute parliamentary blunder by allies of the Chinese leadership — the bill won only eight votes in the city’s 70-member Legislative Council.