New York City has agreed to pay $3 million to the family of Amadou Diallo, the unarmed West African immigrant who was killed in a barrage of gunfire almost five years ago.

On a dark, Bronx street in February 1999, police officers who mistakenly took Mr. Diallo for a rape suspect fired 41 bullets at the 22-year-old street vendor after he reached for his wallet. Mr. Diallo was shot 19 times and died of his injuries.

The four police officers who fired at Mr. Diallo said he resembled a suspected rapist they were seeking, and they said they believed he was reaching for a gun. They were tried and acquitted of charges including murder and reckless endangerment, but the case turned the spotlight on the controversial police practice of racial profiling.

The Diallo family then filed a wrongful death suit against the city, seeking $61 million in damages, $20 million for pain and suffering and $1 million for each of the 41 bullets fired.

The city reached the agreement to pay the Diallo family $3 million on Tuesday, shortly before the case was scheduled to go to trial.

Mayor Michael Bloomberg said he hopes the city has learned from its mistakes. "Not everybody is always in the situation that the textbooks say and we can always learn from ourselves, we have to be able to do that. We also have to remember that money is not a substitute for somebody's life," he said.

The parents of Amadou Diallo issued a statement through their lawyer, saying that they are "very grateful to finally achieve closure."

Pat Lynch, a spokesman for the police union, said the incident was troubling for both sides. "We must remember what a tragedy this was. It was a tragedy for the Diallo family who lost a loved one and it was also a tragedy for those police officers who went to work that day and were put in a very untenable situation; [they] thought their lives were in danger," he said.

Mr. Diallo, who was born in Guinea, had no criminal record. The investigation into his death led the New York City Police Department to clarify its policy against racial profiling. The department says that it prohibits "the use of race, color, ethnicity or national origin as the determinant factor for initiating police action."