Terrified students and professors cowered in classrooms and dorms as a gunman roamed the floors of a building at the University of Nevada, Las Vegas (UNLV), killing three people and critically wounding a fourth before dying in a shootout with police.

The gunman in Wednesday’s shooting was a professor who had unsuccessfully sought a job at the school, a law enforcement official with direct knowledge of the investigation told The Associated Press.

He previously worked at East Carolina University in North Carolina, said the official.

Another law enforcement official identified the suspect as Anthony Polito, 67.

Campus Shooting Las Vegas
A police officer at the scene of a shooting at the University of Nevada (KM Cannon/AP)

Investigators searched an apartment in Henderson, Nevada, late on Wednesday as part of the investigation and retrieved several electronic devices, including Polito’s mobile phone, the official said.

The attack was the worst shooting in the city since October 2017, when a gunman killed 60 people and wounded more than 400 after opening fire from the window of a room at Mandalay Bay casino on the world-famous Las Vegas Strip only a couple of miles from the UNLV campus.

Lessons learned from that shooting – the deadliest in modern US history – helped authorities to work “seamlessly” in reacting to the UNLV attack, Sheriff Kevin McMahill said at a news conference.

At about 11.45am local time, the gunman opened fire on the fourth floor of the building that houses the UNLV’s Lee Business School, then went to several other floors before he was killed in a shootout with two university police detectives outside the building, UNLV police chief Adam Garcia said.

Authorities gave the all-clear about 40 minutes after the first report of an active shooter.

Three people were killed and a fourth was admitted to hospital in a critical but stable condition, police said.

It was not immediately clear how many of the school’s 30,000 students were on campus at the time, but Mr McMahill said students had been gathered outside the building to eat and play games.

If police had not killed the attacker, “it could have been countless additional lives taken”, he said.

“No student should have to fear pursuing their dreams on a college campus,” the sheriff said.

Police did not immediately identify the victims, the attacker or the motive and did not say what kind of weapon was used, although some witnesses reported hearing as many as 20 shots fired.

UNLV professor Kevaney Martin took cover under a desk in her classroom, where another faculty member and three students took shelter with her.

“It was terrifying. I can’t even begin to explain,” Ms Martin said.

“I was trying to hold it together for my students, and trying not to cry, but the emotions are something I never want to experience again.”

Ms Martin said she was texting friends and loved ones, hoping to receive word a suspect had been detained.

When another professor came to the room and told everyone to evacuate, they joined dozens of others rushing out of the building.

Ms Martin had her students pile into her car and drove them off campus.

“Once we got away from UNLV, we parked and sat in silence,” she said.

“Nobody said a word. We were in utter shock.”

Selena Guevara said she got a phone call from her daughter, Markie Montoya, who was in class in the building and heard “gunshots, screaming and yelling” but was not hurt.

“She’s hysterical, telling me ‘I love you’ and so scared,” Ms Guevara said.

Another student, Jordan Eckermann, 25, said he was in his business law class in a second-floor classroom when he heard a loud bang and a piercing alarm went off, sending students to their feet.

Some ran from the room in panic while others heeded their professor’s instructions to stay calm, said Mr Eckermann.

APTOPIX Campus Shooting Las Vegas
Both local and campus police descended on the university (Madeline Carter/AP)

He walked out and locked eyes with a law enforcement officer in a bulletproof vest holding a long gun.

Clothing, backpacks and water bottles lay scattered on the floor.

Mr Eckermann said he mouthed to the officer: “Where do I go?”

The officer pointed to an exit.

Minutes later, when he was outside, Mr Eckermann said he heard bursts of gunshots, totalling at least 20 rounds.

The air smelled of gun powder.

He said he kept walking away from campus, even though he did not know where to go.

Classes were cancelled through Friday at the university, and the UNLV’s basketball game at the University of Dayton, Ohio, was cancelled on Wednesday night because of the shootings.