Reinforced Egyptian security forces today quelled a violent insurrection by armed Moslem fundamentalists after a 24-hour running battle in part of this dusty city on the upper Nile river, 250 miles south of Cairo.

Local authorities said the fighting, which had begun with a raid on the central security forces' headquarters shortly after dawn prayers Thursday, ended at about 6 a.m. today when the last three snipers holed up in the city's souk, or commercial district, were killed.

The officials said 13 persons, including four policemen, had been killed in the fighting, about 40 wounded and another 29 arrested. But hospital sources said 45 people had been killed in the 24 hours of fighting.

Without a doubt the battle in this city, which is known for the militance of its fundamentalists, was one of the worst outbreaks of urban violence in Egypt in recent times and bespoke of the tensions in the country in the wake of Tuesday's assassination of president Anwar Sadat.

More ominous than the violence, however, was the determination, planning and organization with which it was carried out.

Officials here said the attack on the security forces' headquarters in the heart of the city had been carried out by 75 Moslem commandos, armed with Soviet-made AK47 assault rifles and pistols and organized in military-style squads of 15 men each.

The insurgents, according to officials here, were mostly members of the Islamic society Gaamat Islamaya that have sprung up in recent years in 17 universities, including the University of Asyut, which, since the late 1970s has been the scene of frequent clashes on campus between militant Moslems and police.

The attack on Asyut apparently began just after the morning mosque prayers that marked the beginning of the four-day Moslem holiday of Id Al Adha, the feast of sacrifice. According to residents of the town, the clashes started after officials turned down a request to hold a demonstration in honor of the holiday.

The insurgents reportedly commandeered cars in the streets of the city and then converged on the security headquarters, which they succeeded in occupying after a gun battle with its startled defenders.

After occupying the headquarters, the insurgents released prisoners from the jail and gave them arms held in the building, according to an account from one security officer in the town.

From sandbagged positions in the streets around the building, as well as from its windows and roof, the insurgents fought off repeated attempts Thursday by security forces, reinforced by military police and, according to one witness, commandos in battle dress. They finally retreated to a house, across from another security post in mid-afternoon.

The fundamentalists eventually were forced to give up that house as well, and after a brief defense of a third building they occupied, retreated at nightfall into the warren of narrow streets that make up the souk district of this city of 250,000.

There, officials said, the remaining defenders fought sporadically through the night, firing from rooftops as others retreated from the vastly superior, reinforced government security forces that had converged on the city.

The last three snipers were finally killed at 6 a.m. today, although there were reports of occasional shots heard in the city throughout the morning. The battle of Asyut, however, was finally over.

According to one report, the attack was led by Assem Abdel Maged, a former engineering student who was expelled from Asyut University last October. He was believed to have died in the fighting.

By mid-afternoon today the city was gripped by an uneasy calm, its downtown streets virtually deserted except for the patrols of armed security forces at every corner, and most of its shops remained shuttered through the day. Life on the city outskirts, however, appeared to be returning to normal.

Although the Foreign Ministry director, Gen. Osama al-Baz, termed the Asyut clash "not serious" at a press briefing Thursday night, visitors who finally reached here today after having threaded their way past 18 roadblocks by security forces found the situation somewhat worse than that.

The security force headquarters where the attack was centered was pockmarked with bullet holes and one office had two bullet holes on the wall behind the official's desk.

In Cairo, meanwhile, Deputy Prime Minister Fouad Mohieddine announced this afternoon that things were "now under control" in Asyut. He pledged, however, that the government was prepared to take "severe measures" to prevent any repeats of similar incidents.