WASHINGTON — The number of Americans seeking a career in the U.S. diplomatic corps has declined in the first two years of the Trump administration, reaching the lowest level since 2008, according to State Department numbers obtained exclusively by NBC News.

Although President Donald Trump's unpredictable, go-it-alone foreign policy has caused apprehension among some prospective applicants, and led some senior diplomats to resign, the cause of the drop remains unclear.

But coupled with budget pressures and a survey showing declining morale at the State Department, veterans of the diplomatic corps worry that the long-term health of the institution charged with safeguarding America's interests abroad could be at risk if current trends continue.

The competitive process to join the ranks of U.S. diplomats starts with the Foreign Service Officer Test, a demanding exam given three times a year. Between October 2017 and October 2018, only 8,685 people chose to take the test, a 22 percent decline compared to the same period a year earlier, according to the State Department's numbers.

Since 1980, the number of test-takers has dipped below 9,000 in only two other years for which there is complete data — 2000 and 2008, according to statistics provided by former U.S. officials who follow recruitment trends. (According to their data, no tests were given in 1989, 1995 and 1997, and numbers were only available for one testing period in 2007.) The State Department shared figures dating back only to late 2007.

The number of Americans opting to take the test has been on the decline since Fiscal Year 2013, when 21,069 people took the test, according to the State Department.

"It is definitely bad news," said Ronald Neumann, a former senior diplomat now at the American Academy of Diplomacy. "If that keeps going we will lose some people who would have been the brightest stars of tomorrow."

But Neumann said the selection process appears to remain competitive, with roughly 300 slots offered out of more than 8,000 people signing up for the test. "This shouldn't mean the death of the State Department."

Neumann also said that graduate students interested in international affairs have more options compared to 10 or 20 years ago, and many opt for careers in the private sector or in non-governmental organizations.

State Department officials said they saw no cause for concern.

"The numbers are stable," said Carol Perez, who recently took over as the new director general for the State Department overseeing personnel.

She said the quality of applicants remains high and that test results show no drop in the rate of applicants passing the exam.

"We’re working hard to make sure we have the best people on the job and I think we do," Perez told NBC News.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

The number of Americans taking the test so far in the current fiscal year has increased compared to FY 2018, which Perez called an encouraging sign. In February, 3,396 people took the foreign service officer test, up from 2,845 in February last year. Applications for competitive fellowships awarded to new foreign service officers also increased for 2019 compared to the previous year, Perez said.

"It shows to me there's still a lot of interest, and people are thinking about this," she said.

Perez also said that interest in the exam tends to coincide with the unemployment rate, with more applicants taking the exam when the economy is weak. A jump in test takers from 16,125 in fiscal 2009 to 22,281 in fiscal 2010 followed the major recession of 2008, she said.

A review of the numbers over more than three decades shows the number has fluctuated, sometimes rising in the wake of a recession — but also during economic booms.

Since 1980, the number of test takers increased following economic recessions in 1981 and 2001, but did not rise markedly after the recession of 1991. The number also has jumped when unemployment was relatively low.

In the 2000s, the number of test takers rose sharply when the department was engaged in a major hiring and recruiting spree led by then-Secretary of State Colin Powell. State Department officials at the time publicly touted the rise in numbers.

As for the level of interest in the past two years, former diplomats and graduate students said they think perceptions about how the Trump administration has managed the department — and the country's foreign policy — have played a role in discouraging young Americans from choosing a career in government.

New Secretary of State Mike Pompeo laughs as he is introduced by Deputy Secretary of State John Sullivan, left, as he arrives to address State Department employees in Washington on May 1, 2018. Jacquelyn Martin / AP file

Reuben Bigerty, a former senior official at the State Department under the Obama administration and now dean of the Elliot School of International Service at George Washington University, said the decline in interest was a direct result of Trump's actions and policies.

"In both Democratic and Republican administrations, it's always been seen a special privilege to serve as diplomat for the United States. The State Department has always had its pick of some of the finest Americans to do that," Bigerty said.

"The fact that fewer of them are standing up to be chosen, I think can only be read as an indictment of this administration's approach to diplomacy and the people who are charged with carrying it out."

A 2017 survey showed 66 percent of graduate students at schools of international service said they viewed the 2016 presidential election result in a negative way. But the survey, conducted by the Association of Professional Schools of International Affairs and the non-profit Partnership for Public Service, also found a majority of 62 percent planning to apply for positions in international affairs or national security in the federal government.

The Trump administration's proposed budget cuts to the State Department and its isolationist "America First" policies are a frequent topic of conversation in graduate schools, students said, presenting a dilemma for some who otherwise would not hesitate to enter the foreign service.

"In every class, it's the elephant in the room," said one student at American University's School of International Service, who asked not to be quoted by name out of concern his comments could undercut his application. "It's on everyone's mind."

But the student said he still planned to take the foreign service test and hoped to land a position in the State Department. "For a lot of us, we still want to go into the service and make a difference inside."

Orientation courses for incoming foreign service officers try to prepare the new recruits for scenarios in which they are faced with carrying out a policy they deeply disagree with, said Daniel Smith, director of the Foreign Service Institute at the State Department that oversees training.

The new hires study examples of how their predecessors handled ethical and political disagreements, and are encouraged to avail themselves of an internal "dissent channel" that allows employees to express their differences with a policy without facing retribution.

"We try to discuss with them and prepare them for some of the challenges they might face in that regard," Smith said.

But he added: "At the end of the day, this is a service, there is an element of discipline in any service, and you're expected to carry out the policy for the administration."

Diplomats who have left since Trump was inaugurated say that the department suffered a severe blow to morale under the previous secretary of state, Rex Tillerson, and that the jury is still out on his successor, Mike Pompeo, who took over in May.

Pompeo lifted an unpopular hiring freeze imposed by Tillerson, filled some of the dozens of vacancies in senior posts and has vowed to put a top priority on restoring the department's "swagger," ordering his deputies to review how the workforce is trained.

The administration proposed a 30 percent cut to the State Department budget for the past two years, adding to a perception among current and former diplomats that the White House did not value their work. A bipartisan pushback in Congress restored funding for the department.

But while spending on diplomatic security and administration has swelled over the past decade, funding for hiring and deploying foreign service officers overseas — what the department calls "core" diplomatic capability — has decreased from $7.8 billion in 2010 to $3.9 billion in the proposed 2018 budget.

Morale at the State Department has also declined, according to a survey of the best places to work in the federal government by the Partnership for Public Service, a non-partisan organization. Among large federal agencies, the State Department fell to 14th place in 2018, compared to eighth place in 2017. Workers gave low marks to the department's support for diversity, innovation and involving employees in decision-making.

"The State Department has a remarkably valuable proposition to offer," said Max Stier, president of Partnership for Public Service. "But that brand has been dinged lately."

There is a link between morale inside an organization and the desire of people on the outside interested in joining it, he said. The survey numbers "ought to be a wake-up call for people at the State Department," he said. "Pompeo has his work cut out for him."