A decline in the knowledge of science may be ending among 9- and 13-year-olds, but not among 17-year-olds, a government-sponsored survey released yesterday disclosed.

The mixed test results, presented as "good news, bad news" by the National Assessment of Education Progress, represented the second such report on science achievement by American primary and secondary school students.

A panel of experts convened by the assessment group offered no firm explanations of the results. James R. Okey, president of the National Association for Research in Science Training, said that the current stress on reading and mathematics in the nation's schools had taken time away from science education.

John G. Truxal, a professor of engineering at New York University at Stony Brook, said that courses in physics and chemistry have gotten more difficult as fewer students have elected to take them, encouraging teachers to pitch the courses to the brightest students and thus discouraging other students from taking those courses.

As a result, according to rough figures cited yesterday during a press conference, the number of students taking science courses in high school has dropped from about 18 percent in the late 1960s, when attention on space exploration heightened interest, to less than 10 percent now.

Truxal called the results for 17-year-olds "alarming" and suggested that science teachers in high schools should find ways of teaching physics and chemistry that emphazie experiences common to student rather than abstract theories and principles that are difficult to grasp.

The tests were administered to samples of students from all over the country in 1969-70, 1972-73 and 1976-77. About 80,000 students were surveyed in each of the three testing periods.

Among other findings from the most recent tests:

Both 9 and 13-year-old students improved on tests in the biological sciences, while 17-year-old continued to decline. In the physical sciences - physics and chemistry - all three groups showed a continuing decline in performance measured by the tests.

Students in rural communities at all age levels have improved their performance as measured by the tests, rising from scores under the national average to a level above it.

A gap continues to exist between the achievement levels of white students and black students, although 13-year-old black students showed improvement and narrowing of the dirrerence since the last testing period in 1975-76.

Students in the Northeast performed the best on the tests, while students from the Southeast scored lowest.

Males tended to have higher scores than females.