Updated, 11:54 p.m. For more on this story, see the main news article elsewhere on this site.

COLLEGE STATION, Texas — A gunman opened fire on the police near the Texas A&M University campus shortly after noon on Monday, killing at least two people, including a local constable, and wounding at least two others, the police said. The gunman, who was also shot in the ensuing cross-fire, died after he was taken into custody.

The police here identified the constable as Brian Bachmann and said that he had been shot after approaching the gunman’s house, at 211 Fidelity St., about two blocks from campus.

The gunman, who was not identified, opened fire with what a witness said was an automatic weapon, and was then shot by the police and taken into custody. At least two other people, including another officer and a woman in the neighborhood, were wounded and had been taken to local hospitals, the police said.

The reason for the visit by the constable was not immediately known.

Rigo Cisneros, 40, an Army medic who served a tour in Afghanistan, observed the shooting from his home across the street.

“After the fourth or fifth shot, I stuck my head out the door and could hear actual gunfire,” he said by telephone. “I took cover and observed that there was an officer down.”

In video of the scene recorded by Mr. Cisneros and provided to The New York Times, police officers with weapons drawn are seen moving in on a white, one-story home. “Do not move; do not move,” an officer yells at one point. “If you move, you are dead.”

The shooting lasted about 30 minutes, Mr. Cisneros said, as the suspect and the police shot at each other. He said the suspect seemed to be holding either an M4 or M16 assault rifle.

He said that when the shooting stopped, he ran over and found the constable shot in the chest and another officer with less severe wounds. The suspect had been shot multiple times in the legs and upper torso, he said; two passers-by had also been shot. Mr. Cisneros said he tried to give CPR to the constable, who was immobile and had no pulse. When paramedics arrived, Mr. Cisneros said he began attending to the suspect, who had already been handcuffed.

Mr. Cisneros said that the suspect lived across the street but that he did not know him. The suspect was conscious and asked forgiveness for shooting the officers, he said. Mr. Cisneros also said the police told him that law enforcement officials had initially visited the suspect’s house on Monday to deliver an eviction notice.

An image posted on the Web site of a local ABC News affiliate, KTRK-TV, appeared to show a black automatic weapon under a brown sedan. It was not clear from the footage whether the gun belonged to the suspect.

Texas A&M University issued a series of warnings on its Web site, beginning around 12:30 p.m. Central time, when residents near the campus football stadium were urged to remain indoors in the area around Fidelity Street in College Station, about 90 miles northwest of Houston.

Barbara Murphy, 84, who lives near Fidelity Street, said she heard about six or eight gunshots around 12:30. About 10 to 15 minutes later, she said, she heard another round of gunshots.

“We’re doing a lot of remodeling around here, but then I realized it couldn’t just be a hammer,” she said. “About that time, a neighbor called and said don’t go outside.”

Television images from a news helicopter showed single-family homes spaced apart along a dry, tree-lined street. Local sheriffs, state troopers and police officers could be seen scattered around the area, which was cordoned off on Monday afternoon.

In many counties in Texas, constables are elected, and serve legal papers and perform police duties at a local neighborhood level.

Campus police at Texas A&M University said the shooting had occurred entirely off-campus and directed questions to the local police. Fall classes at the university are scheduled to begin on Aug. 27.