Jacob Leggette, 9, of Baltimore, Md., looks in amazement as President Barack Obama blows a bubble while visiting his science exhibit during the annual White House Science Fair in April 2016. Obama started the fair as a way to highlight and encourage STEM education. (Ricky Carioti/The Washington Post)

The nation’s fourth- and eighth-graders have made gains in science, and large racial achievement gaps have narrowed slightly, according to the results of a national science test released Thursday.

In the test administered last year, girls improved faster than boys, narrowing the gender gap at the eighth-grade level and erasing it in the fourth grade.

High school seniors’ science performance has remained flat since the last time the test was administered, in 2009, however, and racial and gender achievement gaps among 12th-graders did not change.

The results come from the National Assessment of Educational Progress, also known as the Nation’s Report Card. The exams — given every two years in math and reading and less frequently in science and other subjects, are widely seen as an important barometer of student performance because they have been given nationwide across a long period of time.

The science test was revised substantially in 2009, making it impossible to compare results to those from tests given prior to that year. The exam, scored on a scale of 0 to 300, measures students’ knowledge and skills in physical science, life science and Earth and space science.

Fourth- and eighth-grade students both scored an average of 154 in 2015, both up from 150 in 2009. White fourth-graders scored an average of 33 points higher than black students and 27 points higher than Hispanic students.

The data released Thursday do not explain the reasons for the gains, which come as the Obama administration has sought to improve science education and highlight its importancefor preparing children to compete for jobs in the modern economy.

Peggy Carr, acting commissioner of the National Center for Education Statistics, which administers the exam, hailed the results. “This is exactly what we like to see: all students improving but students at the bottom of the distribution making faster gains,” Carr said.

The majority of students did not score high enough to be deemed proficient. Among fourth-graders, 38 percent were proficient or advanced in science in 2015, up from 34 percent in 2009; among eighth-graders, 34 percent were proficient or above, up from 30 percent in 2009.

Among 12th-grade students, 22 percent were proficient or above.

Carr said the exam sets a high bar for proficiency, and that a full picture of U.S. science achievement must include students’ performance on international exams.

The United States ranked in the middle of the pack among 65 countries that took the 2012 Programme on International Assessment, which measures science achievement of 15-year-olds.

U.S. students fare better on the Trends in International Mathematics and Science Study (TIMSS): Fifty-seven countries participated in the TIMSS fourth-grade exam in 2011, and just six outperformed the United States.

“We’re not that bad at science,” Carr said.

Parents and teachers have long worried that schools under pressure to raise math and reading test scores are narrowing the curriculum, excluding science and social studies. Carr said that, according to surveys administered alongside the exam, fourth- and eighth-grade teachers are actually spending more time on science than they previously did. It’s not clear whether or how much that contributed to the gains, she said.

The data released Thursday also do not explain why older students’ performance stagnated: Twelfth-graders scored 150 in 2015, the same as they did in 2009. Carr suggested that one reason might be the nation’s rising high school graduation rate, which means that students who previously might have dropped out are now staying in school — and are included in the 12th grade test.

Even so, she said, there’s reason for concern: “Whenever we don’t see movement, we need to pay attention to it.”

State-level results were not released for 12th graders and they varied widely among the states for younger students, from low-scoring Mississippi (where 23 percent of fourth-graders were proficient) to high-scoring New Hampshire (where 51 percent were proficient). Tennessee — which has undergone rapid reforms in recent years, many aligned with Obama administration priorities such as new teacher evaluations — was the only state to show faster-than-average growth at both grade levels.

Locally, Virginia students performed significantly better than the national average. Half of fourth-graders were proficient, more than every state but New Hampshire, and 40 percent of eighth-graders were proficient, putting Virginia behind eight higher-scoring states.

Steven Staples, Virginia’s state superintendent, said he was pleased with the performance but troubled by persistent and large achievement gaps.

“Even though the gaps may be closing slightly, we’re still concerned that those gaps are there, and I think that’s going to be the focus of our work moving forward,” Staples said.

Maryland’s scores were not significantly different from the average. State participation in the exam was voluntary, and scores were not reported for the District of Columbia and Alaska, Colorado, Louisiana and Pennsylvania.