A law enforcement official who had knowledge of the case and spoke on condition of anonymity said the gunman was believed to be dead. Virginia Tech officials said on the school’s website that a weapon was recovered near the second body found in a parking lot on campus. It was not immediately clear if the second body was that of the gunman.

School officials also said there was no longer an active threat Thursday afternoon and that normal activities could resume after an hourslong lockdown.

The school applied the lessons learned nearly five years ago, closing down the campus and warning students and faculty members via e-mail and text message to stay indoors. Thursday’s shootings came as university officials were in Washington appealing a fine that US officials gave them over the school’s response to the 2007 rampage.

The campus swarmed Thursday with heavily armed police. Students hid in buildings, a day before final exams were to begin Friday.

“A lot of people, especially toward the beginning were scared,” said Jared Brumfield, a 19-year-old freshman who was locked in the Squires Student Center since around 1:30 p.m. “A lot of people are loosening up now. I guess we’re just waiting it out, waiting for it to be over.”

The school said a police officer pulled someone over for a traffic stop and was shot and killed. The shooter ran toward a nearby parking lot, where a second person was found dead.

Various alerts were sent to students, and the university is sending updates about every 30 minutes, school spokesman Mark Owczarski said.

The suspect was described as a white man wearing gray sweat pants, a gray hat with neon green brim, a maroon hoodie and backpack.

“It’s crazy that someone would go and do something like that with all the stuff that happened in 2007,” said Corey Smith, a 19-year-old sophomore. He told The Associated Press that he stayed inside after seeing the alerts from the school.

Campus was quieter than usual because classes ended Wednesday and students were preparing for exams. The school said those tests would be postponed.

The shooting came as Virginia Tech was appealing a $55,000 fine by the US Education Department in connection with the university’s response to the 2007 shootings.

The department said the school violated the law by waiting more than two hours after two students were shot to death in their dorm before sending an e-mail warning. By then, student gunman Seung-Hui Cho was chaining shut the doors to a classroom building where he killed 30 more people and then himself.

The department said the e-mail was too vague because it mentioned only a “shooting incident,” not the deaths.

An administrative judge ended the hearing by asking each side to submit a brief by the end of January. It is unclear when he will rule.

Since the massacre, the school has overhauled its alert system and now sends text messages, e-mails, tweets and posts messages on its website. Other colleges and universities have put in place similar systems.

On Thursday, during about a one-hour period, the university issued four separate alerts.

Derek O’Dell, a third-year student who was wounded in the 2007 shootings, was shaken. He was monitoring the situation from his home a couple of miles from campus.

“At first I was just hoping it was a false alarm,” he said. “Then there were reports of two people dead, and the second person shot was in the parking lot where I usually park to go to school, so it was kind of surreal.”