Five people died after a heavily armed man entered a lecture hall at Northern Illinois University and began shooting on Thursday afternoon.
The university website said the gunman, who shot and killed himself, was a graduate student in sociology who last enrolled in spring 2007.
The man killed four women and a man in a "brief, rapid-fire assault," university president John Peters said.
In all, there were 21 victims, the university website said.
The gunman and three victims died at the university. Two others died in hospital, Peters said.
The victims were initially taken to the Kishwaukee Community Hospital in DeKalb, Ill., where the school is located. On its website, the hospital said it had admitted 18 victims, but by 8:50 p.m. CT, eight had been released.
The gunman, armed with a shotgun and two handguns, opened fire in a lecture hall at the university around 3 p.m. CT, prompting students to flee.
"This thing started and ended in a matter of seconds," university police Chief Donald Grady said.
Peters told a news conference that witnesses said "someone dressed in black came out from behind a screen at the front of the classroom and opened fire with a shotgun."
Students fled in panic
"People were crawling on each other, trampling each other," said student Desiree Smith, who lay down and worked her way toward the back of the lecture hall.
"As I got near the door, I got up and I started running."
Student Jerry Santoni said he saw the gunman shoot at the teacher.
"After that, I proceeded to get down as fast as I could," he said.
The teacher was wounded but is expected to recover, Peters said.
A student who was in the lecture hall when the shooting began told the university paper that the scene was chaotic.
"Some girl got hit in the eye, a guy got hit in the leg," George Gaynor told the Northern Star.
The campus is about 100 kilometres west of Chicago.
At 4:15 p.m. CT, the university said "the immediate danger has passed. The gunman is no longer a threat."
The university cancelled Friday's classes, and asked students to call home.