Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

A California college student wielding a knife went on a rampage at the University of California’s Merced campus Wednesday, stabbing four people before he was shot dead by police, authorities said.

The violence broke out during an 8 a.m. class in a second-floor classroom of the school's Classroom and Office Building. The suspect was taken down within 20 minutes, the school said, and all those stabbed are expected to recover.

The attacker stabbed a student inside the classroom and then stabbed a contract worker who heard the sound of a struggle and came to investigate, officials said.

"We thought it was a fight going on and we heard people screaming," Jacob Rodriguez, who was painting a wall with the worker who was stabbed, told NBC News.

"My co-worker opened the door to see if there was a fight going on and if they needed help. He said the teacher looked at him and said ‘no,’ and then the guy ran out and attacked my co-worker,” Rodriguez said.

"He attacked my co-worker and then he came towards me and I grabbed a ladder and put a ladder between me and the guy and he ran off downstairs," Rodriguez said.

Police said the suspect ran from the classroom and down a flight of stairs and stabbed a second student and a student adviser before he was spotted by officers.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

"When the suspect turned toward the officers, an officer-involved shooting occurred and the suspect succumbed to his injuries," UC Merced Police Chief Albert Vasquez said.

The suspect’s name was not released pending notification of next of kin. He was described as a “young adult” who was a California resident but was living on campus.

The university first reported that five people were stabbed, but later corrected that number to four. “Their injuries, thank God, appear not to be life threatening,” UC Merced Chancellor Dorothy Leland said.

A motive in the rampage was not released. Authorities called in a bomb squad to examine the attacker’s backpack as a precaution, officials said.

The worker who went inside the classroom was being called a hero for interrupting the attack on the student.

Merced County Sheriff SWAT members enter the University of California, Merced campus after a stabbing spree on campus Nov. 4, 2015. Andrew Kuhn / Merced Sun-Star via AP

"The contract worker actually went in thinking it was a student fight and ended up stumbling onto this stabbing in progress," Merced County Sheriff Vern Warnke said. "I actually think that he, through his actions, saved this one student’s life."

Rodriguez said he and a third worker went over to a balcony and looked down as the suspect ran into the street. They saw him stab another student and a woman, who was knifed in the back and the chest, he said.

“It was kind of like, is it real or a Halloween prank?” Rodriguez said.

The student adviser who was stabbed was sitting down when she was suddenly attacked, Warnke said.

"Just sitting, literally minding her own business and he came up behind her, stabbed her front and back,” he said.

The suspect used a hunting style knife with a fixed blade of between 8 to 10 inches in the attack, authorities said. The weapon was found about four feet away from where he was shot, Vasquez said.

"We are fortunate that it was not worse, and we thank our UC Merced police officers for their quick and heroic actions in ending this situation quickly," Vasquez said.

Rodriguez said his co-worker was stabbed in the upper leg. They drove him to the hospital “because there were people injured worse than he was," Rodriguez said.

The campus was on lockdown while police investigated, and classes were cancelled for the day. The college will remain closed Thursday, but expected to reopen Friday, Leland said.

UC Merced is offering counseling services to witnesses or to anyone else affected, Leland said.

UC Merced is a relatively recent addition to the University of California system, and opened for graduate students in 2004 and for undergraduates in 2005. It has over 6,000 students, with around 2,100 of those living in residence halls on campus.