Kenya Defence Forces soldiers move behind a thicket in Garissa town in this photograph taken from a mobile phone.

The death toll in the attack by Somali Islamists on a university in northeastern Kenya on Thursday has risen to 147 and the siege has ended, the country's disaster response agency said.

Gunmen from the Islamist militant group al Shabaab stormed a Kenyan university campus on Thursday, killing and wounding dozens of students and staff.

Police and soldiers surrounded the Garissa University College and exchanged gunfire with the attackers throughout the day.

Sheikh Abdiasis Abu Musab, an Al Shabaab's spokesman, said the gunmen were holding Christian hostages inside.

"We sorted people out and released the Muslims," he told Reuters.

Interior Minister Joseph Nkaissery did not specify precisely how many students, staff or security personnel had died but said four al Shabaab fighters were killed.

However, he cautioned that "the operation is ongoing, anything can happen".

One Kenyan policeman at the scene of the attack said six al Shabaab fighters, from the original 10 that stormed the university campus, remain holed up inside, along with about 100 student hostages.

Al Shabaab, who carried out the deadly attack on the Westgate shopping mall in Nairobi in 2013, claimed responsibility for the pre-dawn raid on the campus in Garissa, a town 200 km (120 miles) from the Somali border.

The group has links to al Qaeda and a record of raids on Kenyan soil in retaliation for Nairobi sending troops to fight it in its home state of Somalia.

Kenyan police chief Joseph Boinet said the attackers had "shot indiscriminately" while inside the university compound.

One image provided by a local journalist showed a dozen blood-soaked bodies strewn across a single unversity classroom.

Some students had managed to escape unaided.

"We heard some gunshots and we were sleeping so it was around five and guys started jumping up and down running for their lives," an unnamed student told Reuters TV.

Authorities offered a 20 million shilling ($215,000) reward for information leading to the arrest of a man called Mohamed Mohamud, described as "most wanted" and linked to the attack.

Police chief Boinet said Kenya had imposed a dusk-to-dawn curfew on four regions near the Somalia border.

TOURISM AND RELIGION

Al Shabaab, which seeks to impose its own harsh version of sharia law, has separated Muslims from Christians in some of its previous raids in Kenya, notably late last year in attacks on a bus and at a quarry.

Its repeated raids, together with attacks on churches by home-grown Islamist groups, have strained the cordial relations between Kenya's Muslim and Christian communities.

Having killed more than 200 people in Kenya over the past two years, Al Shabaab has also brought the tourism industry to its knees.

Thursday's attack undermined a renewed drive by President Uhuru Kenyatta to persuade foreigners the country is now safe to visit.

On Wednesday, he had urged Kenyans abroad to help attract tourists back despite the wave of militant violence, criticising a warning from Australia of a possible attack in Nairobi and an advisory from Britain urging its citizens to avoid most coastal resorts.

Grace Kai, a student at the Garissa Teachers Training College near the university, said there had been warnings that an attack in the town could be imminent.

"Some strangers had been spotted in Garissa town and were suspected to be terrorists," she told Reuters.

"Then on Monday our college principal told us ... that strangers had been spotted in our college... On Tuesday we were released to go home, and our college closed, but the campus remained in session, and now they have been attacked."

Many Kenyans living in the crime-ridden frontier regions blame the government for not doing enough to protect its citizens from the militants.