Two of those stabbed were transported for treatment via helicopter, the school said on Twitter, while the two others were treated on campus.
"All conscious," the university tweeted about the victims.
The attacker was a California resident who was living on campus, Merced County Sheriff Vern Warnke said. The victims were identified as two students, a staff member and a contract employee at the school.
Authorities have not released a motive and it's not known what relationship, if any, existed between the assailant and the victims, said James Leonard, a school spokesman.
Warnke said the attacker entered a classroom at about 8 a.m. carrying a hunting knife with an 8-inch to 10-inch blade and stabbed one of the students.
The contract worker, thinking it was a fight, went into the classroom and "ended up stumbling upon the stabbing in progress. I think, through his actions, that he ended up saving this student's life," Warnke said.
Outside the classroom, the suspect attacked a female staff member and slightly injured the second student, Warnke said.
The suspect fled the building and was chased by two police officers, said UC Merced Police Chief Al Vasquez.
"When the suspect turned toward the officer, an officer-involved shooting occurred and the suspect succumbed to his injuries," Vasquez said.
Warnke said the bomb squad was called as a precaution because the suspect carried a backpack.
"Events like this happen elsewhere, but not at UC Merced, which may be still small in student body but large in its sense of community — yet, it has happened," Chancellor Dorothy Leland said in a statement
on the school webpage. She said the injuries were not believed to be life-threatening.
Merced is about 130 miles southeast of San Francisco.
The school initially reported five people were stabbed, but later said the figure was four, said Lorena Anderson, a school spokeswoman. The school first said all of the victims were students, but later said that not all of them were students.
The school Twitter page said
that classes would not be held Thursday.