Shots were fired in the air and special forces came to reinforce the police before the youths dispersed, chanting slogans against the AKP.
The HDP saw its share of the vote fall to 10.4 per cent, although it will actually have more MPs in the new parliament.
In Diyarbakir itself it lost one seat to the AKP, but kept nine out of 11.
Ziya Pir, who was reelected, said the party had suffered from the rise in violence since the AKP ended peace talks with the PKK guerrilla movement.
"There were two factors," he said on the steps of the party offices after the teargas had cleared. "Because of the fighting in this area, people don't want to have fighting and they voted AKP, even if they are no AKP voters they voted for them to have normal lives. The second factor is our leaders always said that we would have more than 13 per cent, maybe 14 per cent or 15 per cent. It was a bad strategy because people thought 'OK, we will have no problem with the barrier of 10 per cent [needed to be passed to have MPs] and they didn't go to the elections."
At national level the AKP won nearly half the votes cast, giving it a clear majority in parliament.
That means it will not have to form a coalition government.
Its inability to do so was the reason for Sunday's rerun.
The second-largest party, the secular, nationalist People's Republican Party (CHP) suffered slight losses, while the more right-wing Nationalist Action Party's vote also fell.
The AKP's unexpected triumph will be a boost to Erdogan's ambition to concentrate more power in his hands, although the party does not have enough seats in parliament to change the constitution, as he would like to do, unless it can win the MHP's support.