Fighting between Libyan government forces and rebels spilled over the country’s western border into Tunisia on Friday, with troops loyal to Moammar Gaddafi firing indiscriminately in a Tunisian border town, witnesses said, and provoking an angry reaction from the authorities in Tunis.

Control of the border post has swung back and forth during the conflict. Rebels captured it a week ago, but government forces regained control Thursday. By Friday morning, the rebels said they were back in charge of the post, key to an important lifeline to towns and villages they control in Libya’s remote Western Mountains.

Earlier in the morning, Libyan government troops riding in more than a dozen SUVs and armed with antiaircraft guns and rocket launchers had burst through the border and into the Tunisian border town of Dahiba, apparently in pursuit of rebels, witnesses told news agencies. Some of the intruders were reported killed and wounded as they clashed with the Tunisian army, and at least one Tunisian resident was also hurt when shells from the Libyan side landed in Dahiba.

The Libyan troops were captured by the Tunisian army and eventually taken back across the border at another, unofficial crossing point, the al-Jazeera television network reported.

Tunisia’s Foreign Ministry expressed its “extreme indignation” to the Libyan government after the fighting spilled into its territory. About 1,000 Libyans fled the town of Wazin on the Libyan side to take refuge in Tunisia. The rebels staged a counterattack, and fierce fighting ensued.

The main crossing into Tunisia, two hours’ drive to the north, remains firmly under Libyan government control.

In the southeastern desert, meanwhile, government forces Thursday attacked and entered a remote town in another day of clashes across the country.

Forces loyal to Gaddafi also continued to shell the besieged western city of Misurata, killing at least 10 civilians and wounding at least 30, a rebel spokesman said.

Rebel officials said an apparent NATO airstrike had also accidentally killed at least 10 rebel fighters near Misurata’s port Wednesday, on the same swampy road where NATO had destroyed a convoy of government forces the day before.

“If it was NATO, it means our boys are completely wrong to go there,” Mohamed Ali, a rebel spokesman, said via Skype. “They were told not to go there by commanders, and we accept responsibility for this mistake. No one in Misurata is blaming NATO for what happened.”

A NATO spokesman told the Associated Press the jets had struck several combat vehicles about 10 miles southeast of Misurata’s port Wednesday, targeting an area where they had broken up a large group of pro-Gaddafi forces the day before.

On Friday, Brig. Gen. Rob Weighill, a NATO spokesman, said the alliance had no way to verify whether its aircraft were responsible.

If the strike was by NATO warplanes, it would mark the third mistaken attack on rebel fighters in opposition territory since the airstrike campaign began several weeks ago.

Libyan state television claimed that Gaddafi’s troops had also taken control of the town of Kufra, in the southeastern desert, “and purified it of the armed gangs,” as the government calls the rebels.

But rebels in Benghazi denied that the town had fallen.

“Gaddafi’s forces have been shelling Kufra since this morning, and in the afternoon they entered the town. But they are not in full control. The battle is not over, and the situation is unclear,” rebel spokesman Mohamed al-Muntasser said.

In Misurata, Ali said that government troops stationed to the east and south continued to rain artillery and rocket fire on the city. He said NATO planes could be heard throughout the day and were striking in and around Misurata, adding that he hoped they would locate the sources of the shelling. “There is some more work to be done to make Misurata safe,” he said.

Rebel leaders have expressed frustration that NATO was not doing more to protect Misurata’s port, the city’s lifeline, from attacks by Gaddafi’s forces. Nevertheless, they acknowledge the city would have been overrun by now if it were not for the coalition.

Aiman Abu Shahma, a doctor in Misurata, said shells landed Thursday within a few hundred yards of the clinic where he works.

“Every day he is shelling us with rockets, but rockets cannot occupy our city,” he said, adding that he was happy with NATO and that he hoped the alliance would carry out more airstrikes, notably on Gaddafi’s Bab al-Aziziyah compound in Tripoli.

Fadel reported from Benghazi.