A further eight people remain in a critical condition after the attack on Lhubiriha secondary school in Mpondwe.
Boys who were staying in dormitories at the school are among the dead.
The Allied Democratic Forces (ADF) – a Ugandan group based in the Democratic Republic of Congo (DRC) – have been blamed for Friday’s attack.
Many of the bodies were transferred to Bwera Hospital, national police spokesperson Fred Enanga said.
The attack happened at around 23:30 local time (20:30 GMT) on Friday at the school in the Kasese district in western Uganda.
Over 60 people are educated at the school, most of whom live there.
ADF rebels burnt a dormitory and a food store was also looted during the incident, Mr Enanga said.
Some of the boys were burnt or hacked to death, Major General Dick Olum from the Ugandan army told the media.
Others at the school, mostly girls, have been abducted by the group, he added.
Some of the bodies are said to have been badly burnt and DNA tests will need to be carried out to identify them.
The attackers are said to have torched the students’ mattresses and are also thought to have detonated bombs in the region.
Members of the wider community are possibly among the dead. A number of students remain unaccounted for.
Soldiers are pursuing ADF insurgents towards the DRC’s Virunga National park – Africa’s oldest and largest national park which is home to rare species, including mountain gorillas.
Militias including the ADF also use the vast expanse, which borders Uganda and Rwanda, as a hideout.
“Our forces are pursuing the enemy to rescue those abducted and destroy this group,” defence spokesperson Felix Kulayigye said on Twitter.
The Ugandan army has also deployed planes to help track the rebel group.
Uganda and the DRC have held joint military operations in the east Congo to prevent attacks by the ADF.
Security forces had intelligence that rebels were in the border area on the DRC side for at least two days before Friday night’s attack, Major General Olum said.
The deadly episode follows last week’s attack by suspected ADF fighters in a village in the DRC near to the Ugandan border. Over 100 villagers fled to Uganda but have since returned.
The attack on the school, located less than two kilometres (1.25 miles) from the DRC border, is the first such attack on a Ugandan school in 25 years.
In June 1998, 80 students were burnt to death in their dormitories in an ADF attack on Kichwamba Technical Institute near the border of DRC. More than 100 students were abducted.
The ADF was created in eastern Uganda in the 1990s and took up arms against long-serving President, Yoweri Museveni, alleging government persecution of Muslims.
After its defeat by the Ugandan army in 2001, it relocated to North Kivu province in the DRC.
The group’s principal founder, Jamil Makulu, was arrested in Tanzania in 2015 and is in custody in a Ugandan prison.
ADF rebels have been operating from inside the DRC for the past two decades.
In 2021, suicide bombings in Uganda’s capital Kampala and other parts of the country were blamed on the ADF.