Maryland high school students ranked first in the nation for their scores on Advanced Placement exams, a key measure of college preparedness, while Virginia’s graduating seniors last spring slipped from third nationally to fifth, according to results released Wednesday.

Virginia’s dip came despite increases in the percentage both of students taking AP tests and earning a college-ready score of 3 or higher, state officials said. AP tests are graded on a scale of 1 to 5, and students who earn a 3 or better can be eligible for college credit.

Two other states — Massachusetts and Florida — overtook Virginia in the rankings. Virginia officials attributed the shift to state-funded AP incentive programs in those states. Virginia had held steady at third nationally for five years.

“The trend line continues to be very positive in Virginia,” said Charles B. Pyle, spokesman for the state Department of Education. “What’s happened is we have been surpassed by a couple of states that have done some things on the ground to increase participation.”

The national rankings come as part of an annual “AP Report to the Nation” released by the College Board, which administers the exams.

Across the country, participation and performance were up, with 954,070 students in the Class of 2012 taking at least one AP exam during high school and nearly 20 percent of graduates scoring a 3 or higher.

But the College Board also said many students with the potential to succeed on the test, including a disproportionate share of minority students, had not participated in AP.

In Maryland, officials celebrated the state’s fourth year in a row in the top ranking. Maryland officials also noted that a College Board analysis, based on new data, shows that Maryland’s top ranking has actually extended for seven years.

In Maryland, 29.6 percent of high school seniors in the Class of 2012 scored a 3 or higher on one or more exams, which are given across a range of subjects. In Virginia, 27.2 percent of high school seniors achieved that distinction. In the District, 9.9 percent did, compared to 6.6 percent in 2011.

D.C. school officials said the city has seen an upward trend in AP achievement. Last year, 1,512 traditional public and charter school graduates took an AP exam, compared with 584 graduates in 2002. The number of those who scored a 3 or higher rose to 389 graduates from 234 in 2002.

Ovetta Wiggins contributed to this report.