Officials from the U.S. Department of Justice and Montgomery County will announce today the end of an almost four-year civil rights review of police, according to sources who say the county has agreed to improve the way it tracks complaints against officers and the race of people pulled over in traffic stops.

The agreement, reached yesterday after almost three months of confidential negotiations, will end the possibility of legal action that accompanied the federal investigation into allegations of racial harassment against county police officers.

Similar reviews have led to federal action against law enforcement agencies in New Jersey and Ohio, but Montgomery officials have worked to avoid becoming the first Maryland jurisdiction to face federal sanctions. If the county does not fulfill the agreement, the Justice Department could still file a suit.

The federal investigation has been described by County Executive Douglas M. Duncan (D) as a "dark cloud" over the department since the probe began almost four years ago in response to complaints of racial harassment by county police. The allegations were first brought to the Justice Department's attention by the local NAACP chapter.

Under the agreement, according to two sources familiar with its contents, the county will computerize internal affairs records now kept on index cards, step up diversity training courses and record the race of every driver pulled over by police. Until now, the race of only those drivers who receive tickets has been tracked by the department.

In addition, the county will be required to hire a consultant to implement the agreement and issue quarterly progress reports, according to sources. The consultant will be selected by the county, Justice Department officials and the Fraternal Order of Police chapter that represents most of the county's 1,032 officers.

Montgomery, Justice Department and FOP officials would not comment on the agreement last night. Assistant U.S. Attorney General Bill Lann Lee is scheduled to be at a news conference today to outline the agreement, sources said.

Last year, friction between county police and the minority community increased after two traffic stops ended in the fatal shooting of an African American in a two-week period. Neither incident was part of the Justice Department review.

In the course of the investigation, sources say, Justice Department officials reviewed more than 600 internal affairs cases and 150 complaints forwarded to the agency by the NAACP chapter. Among the key findings was evidence that, from 1997 to 1998, county police issued 21 percent of traffic tickets to African American drivers; blacks account for 12 percent of the county's population.

Justice Department officials suggest that the data show that Montgomery police treat African American drivers differently during traffic stops, sources say.

But the review did not find evidence that any Montgomery police officer used excessive force or violated civil rights laws, though Justice Department officials counter that the review focused on the agency, not individuals. The agreement does not require the county to make specific personnel changes.

"It's a step in the right direction and is long overdue," said Jorge Ribas, president of the Montgomery County Civic Federation, a coalition of civic groups. "The whole purpose of this wasn't to look for a scapegoat, but to clear the air."

According to sources familiar with the negotiations, Montgomery County agreed to begin computerizing internal affairs records now kept on 3-by-5-inch cards. The agreement also calls on the county to resolve internal affairs cases within 90 days. Until now there have been no time limits.

The county did agree to upgrade the rank of the internal affairs manager from lieutenant to captain, giving the officer a more direct link to the police chief.

Under the agreement, police officers will also be required to note the race, sex and date of birth of every driver they stop on a public road, according to a source familiar with the negotiations.

FOP officials worried that the additional data could unfairly suggest that a police officer was discriminating by race if, for example, he worked in a neighborhood where minorities account for much of the population. So officers will not write badge numbers on the tickets, but instead will be given a group number shared by six to eight other officers working the same day and shift.

The log sheets, which have yet to be designed but could be similar to ones used in the Pittsburgh Police Department, will be compiled and analyzed by the consultant who will issue results in public quarterly reports.

The FOP will have four weeks to ratify the agreement. Once it does, the county will have a series of deadlines to meet. It will be required to have the agreement in place, including new computer systems and a consultant, within 120 days of its approval by the police union.