Student enrollment is falling at most of Maryland’s and Virginia’s community colleges, echoing a national trend in a sector of higher education closely tied to the economy.

There were 190,528 students in Virginia’s 24 public two-year colleges in fall 2013, according to new data from the State Council of Higher Education for Virginia. That represented a drop of 2 percent from the previous year and 3 percent from three years earlier.

The declines are steeper in Maryland. Data from the Maryland Higher Education Commission show that there were 139,198 students in the state’s 16 community colleges in the fall. The total was down 4 percent since 2012 and nearly 6 percent since 2010.

The numbers underscore a challenge for community college leaders across the country: Their schools, which provide low-price education for a large number of older and returning students, often trend in the opposite direction of the nation’s economy.

When the economy tanks, demand usually surges for seats in community colleges as people who are out of work are seeking new credentials to improve their job prospects. But when the economy shows improvement, the demand slackens.

That pattern held true in the aftermath of the 2008 financial crisis. Some colleges were so besieged that students couldn’t get into classes they needed, and some offered classes at unusual hours to pack students into crowded facilities.

“The truth of the matter is that during the recession, we were the economic recovery plan for a lot of Virginia families,” said Jeffrey Kraus, assistant vice chancellor for public relations for the Virginia Community College System.

Now there is a retrenchment. The National Student Clearinghouse Research Center reported that community college enrollment nationwide fell 3 percent last fall after a nearly identical annual decline in fall 2012.

At Montgomery College, the largest community college in Maryland, fall enrollment was 26,155. That was nearly 5 percent lower than the head count the previous year, but it was about the same as the total in 2010. Montgomery College President De­Rionne P. Pollard said its governing board is pondering how to ensure that the college generates enough revenue to support its highly regarded academic programs.

Pollard said she wants “a laserlike focus” on keeping dropouts to a minimum. She said the trick is not just to recruit new students: “We have keep the ones that we have.”

Prince George’s Community College enrollment was 13,574, down slightly from fall 2012 and down 8 percent since 2010.

The largest enrollment drop for a public two-year college in Maryland since 2010 was 24 percent, at Baltimore City Community College. Howard Community College had the largest gain in that time — 7 percent.

The University of the District of Columbia operates a community college with 2,686 students as of fall 2013, down 5 percent from the year before.

In Virginia, the largest decline in the two-year sector since 2010 was at Southwest Virginia Community College, at 30 percent. The most growth in that time occurred at Northern Virginia Community College — up nearly 6 percent. NVCC, which enrolled 51,803 students as of last fall, is one of the country’s largest community colleges.

NVCC President Robert G. Templin Jr. said the school “has made a concerted effort over the last eight or nine years” to reach out to students who might be the first in their families to go to college. Many are from minority, immigrant or low-income families in Fairfax, Prince William, Loudoun and Arlington counties. “We help them navigate the higher education landscape, which is pretty difficult if no one in your family has ever gone,” Templin said.

NVCC also is a major provider of transfer students to the state’s four-year institutions, including nearby George Mason University.

Kraus, the spokesman for the state system, said the statewide enrollment drop shows that two-year colleges must intensify their marketing. Many people don’t know that certificates or two-year degrees in certain fields can be a steppingstone to a well-paying career, he said.

“We need to go out and be talking to people who otherwise are not hearing the message of higher education,” Kraus said. “Part of it is breaking through that ‘bachelor’s or bust’ mentality that a lot of folks have.”