NEW YORK (AP) _ NBC ''Nightly News'' with Tom Brokaw was the top-rated evening news program last week, while Dan Rather and the CBS ''Evening News'' fell to third place for the first time in nearly five years.

NBC's news program had a 9.9 rating and 22 share, ABC's ''World News Tonight'' with Peter Jennings had a 9.7 rating and a 21 share, and CBS had a 9.4 rating and a 21 share in the weekly ratings compiled by the A.C. Nielsen Co.

''This may be a true changing of the guard,'' said Gerald Jaffe, NBC's vice president for research projects. He said it was the first time CBS had run third in the news competition since October, 1981.

''It firmly indicates that the news race is neck and neck and there no longer is a dominant network,'' said Carol Olwert, ABC's director of news information.

''The race now is very close. No one is going to be winning every week,'' Jaffe said, predicting that each network would also spend time in third place in the summer race.

''The only trend that is apparent,'' said George Keramidas, ABC's vice president for research, ''is that the network news race is too tight to predict.''

NBC also won the weekly ratings, with the Thursday night lineup of ''The Cosby Show,'' ''Family Ties,'' ''Cheers'' and ''Night Court'' taking the top four places.

''Growing Pains'' on ABC was fifth, CBS' ''Newhart'' and ABC's ''Who's the Boss?'' tied for sixth, followed by ''Kate & Allie'' on CBS, ''Miami Vice'' on NBC and ''Moonlighting'' on ABC. The first eight programs were comedies, which traditionally repeat better than other TV forms, particularly serials.

NBC had 16 of the top 30 shows, while ABC and CBS had seven each. NBC won the prime-time competition with a 13.0 rating, followed by ABC at 10.7 and CBS at 10.0.

Each rating point represents 859,000 homes with television. The share is the portion of sets in use during the time period.

While pleased with ABC's third consecutive week as runner-up, Keramidas wasn't predicting that the fight for second place would last beyond the summer. CBS is without its highly rated Friday serials, ''Dallas'' and ''Falcon Crest,'' while its ''Knots Landing'' is limping along in 55th place with repeat episodes.

With summer prime time reduced to a rerun race, the news competition is being closely watched.

''If you track the numbers over the last couple of weeks, and the next couple of weeks, you'll find that it's very close,'' said Ann Morfogen, director of information for CBS News. ''I expect that it will be this close through the summer, and we'll see what happens in the fall.''

Last week, it was a question whether NBC won or CBS lost. NBC's rating was exactly the same as a week earlier, while CBS fell from a 10.1 two weeks ago to a 9.4 last week.

Here is how the race has gone since the last week of May, when CBS ran its string of consecutive No. 1 finishes to 213:

Week of May 25 - CBS 9.9, NBC 9.9, ABC 9.2.

Week of June 1 - NBC 10.4, CBS 10.1, ABC 10.0.

Week of June 8 - CBS 10.3, NBC 9.7, ABC 9.4.

Week of June 15 - CBS 10.1, NBC 9.9, ABC 9.3.

Week of June 22 - NBC 9.9, ABC 9.7, CBS 9.4.

Network executives cited no special programming or schedule interruption which might account for the bouncing numbers in the past three weeks. In the weeks of May 25 and June 1, however, CBS News had been hurt by the pro basketball playoffs, which pre-empted the news in some West Coast markets.