Protesters have stormed Macedonia's parliament and attacked legislators after an ethnic Albanian was elected as parliament speaker.

Clashes over several hours on Thursday injured 77 people, including 22 police officers and several MPs, authorities said.

Dozens of protesters, some of them masked, broke through a police cordon after the opposition Social Democrats and parties representing Macedonia's ethnic Albanian minority voted to name Talat Xhaferi as parliament speaker.

Shouting, hurling chairs and grabbing camera tripods abandoned by startled journalists, the protesters attacked parliamentarians, including opposition leader Zoran Zaev, who was seen bleeding from the forehead.

TV footage showed a bloodied Zaev and other Social Democrat politicians surrounded by protesters waving national flags, shouting "traitors" and refusing to allow them to leave.

Many of the protesters were supporters of former prime minister Nikola Gruevski, whose nationalist party won elections in December but did not get enough votes to form a government on its own.

He has been struggling to put together a coalition government and his supporters have been holding nightly street rallies for two months across the country to protest against the political situation.

A tense standoff lasted for three hours, and hundreds of protesters swarmed through the parliament building.

Police said 30 legislators and a number of journalists who had been trapped inside were eventually evacuated safely.

After being initially overwhelmed, police fired flash grenades and clashed with protesters, expelling them from the building.

"The scariest thing is that this was allowed to happen," Ivana Jordanovska, a political activist, told Al Jazeera from Skopje.

"For more than two years, we have seen how the police act when anti-government protests take place. And now [when the opposition is targeted], the police did nothing. The police was absent."

Neighbouring Albania's foreign ministry reacted to the violence, saying it was monitoring "the escalation of the situation in Macedonia with great concern".

Greece's foreign ministry said it was concerned its neighbour Macedonia may be "sliding into deep political crisis".

A ministry statement expressed "sadness and concern" and called on Macedonia's political rivals to show a "spirit of compromise and collaboration".

Gruevski called for people to "calm down" after Thursday's incident.

Gruevski and his nationalist VMRO-DPMNE party ruled Macedonia for a decade until December last year when the election saw VMRO-DPMNE secure 51 seats in the 120-seat parliament - two more than the SDSM - but the conservatives failed to reach a deal with kingmaking Albanian parties.

Although Zaev reached an agreement with the Albanian groups, President Gjorge Ivanov refused to give him a mandate to form a government, leaving the country without a functioning leadership.

An ally of Gruevski, the president expressed concern over the controversial demand of Albanian parties that Albanian be made an official language across Macedonia.

Critics of the demand feared it could lead to the break-up of the country of about two million people - a quarter of whom are ethnic Albanians.