The director of the U.S. Census Bureau is resigning, leaving the agency leaderless at a time when it faces a crisis over funding for the 2020 decennial count of the U.S. population and beyond.

John H. Thompson, who has served as director since 2013 and worked for the bureau for 27 years before that, will leave June 30, the Commerce Department announced Tuesday.

The news, which surprised census experts, follows an April congressional budget allocation for the census that critics say is woefully inadequate. And it comes less than a week after a prickly hearing at which Thompson told lawmakers that cost estimates for a new electronic data collection system had ballooned by nearly 50 percent.

“It’s like two trains going down the track toward each other, with Republicans decrying the budget overrun and Democrats saying the census has been underfunded,” Phil Sparks, co-director of the Census Project, a watchdog organization, said of the May 3 hearing before the House Appropriations subcommittee on commerce, justice and science. “This puts the census in the crosshairs both ways.”

No successor for Thompson was announced. A Commerce Department spokesperson said an acting director would be designated “in the coming days” and the position would be filled permanently “in due course.”

The decennial count typically requires a massive ramp-up in spending in the years immediately preceding it, involving extensive testing, hiring and publicity. However, in late April Congress approved only $1.47 billion for the Census Bureau in the 2017 fiscal year, about 10 percent below what the Obama administration had requested. And experts say the White House’s proposed budget for 2018, $1.5 billion, falls far below what is needed.

Compounding the problem, the bureau had hoped to implement a new system that relies more heavily on electronic data collection than in the past. That plan was announced after Congress told the bureau that the cost of the 2020 count could not exceed the cost of the 2010 count; the new system was promoted as a cost-saving measure.

But at the May 3 hearing, Thompson said that a $656 million cost estimate from 2013 for the new system had been off and the current projected cost was $965 million. Despite this, he told the committee that the bureau was “progressing well” toward being ready for 2020.

Rep. John Abney Culberson (R-Tex.), who chairs the committee, said the projected increase was “a real source of concern” and demanded to know how the bureau planned to cut costs.

Neither Census Bureau nor Commerce Department officials responded to questions about why Thompson is leaving now and whether his departure was unexpected. His five-year term expired in December, but he had been widely expected to stay on through at least the end of this year.

“I saw him as recently as two weeks ago, he was feeling very good about where things were, so I must say that this comes as a surprise, and a sad surprise, that he would feel he needed to do this,” said Kenneth Prewitt, who was director during the lead-up to the 2000 Census, when Thompson was associate director. “He’s a very, very competent man.”

In announcing Thompson’s retirement, Commerce Secretary Wilbur Ross thanked him for his three decades of public service, adding, “Your experience will be greatly missed.”

In a statement released by the Census Bureau, Thompson said resigning now “will allow . . . Secretary Wilbur Ross and the current administration sufficient time to put the proper leadership in place to guide the Census Bureau through the 2020 Census.”

Thompson met with Ross on Monday, said people with knowledge of the situation.

A former Capitol Hill staffer who is knowledgeable about the census said Congress’s mandate for the 2020 Census to cost no more than the 2010 one was unrealistic.

“They’re not accounting for inflation; they’re not accounting for the 30 million more Americans, for the fact that people don’t have hard [telephone] lines anymore. And you’re going to do the census for the same amount of money? That’s not possible.”

He said he didn’t think Thompson had been pushed out, given that there is no clear successor to step in. “His resigning was surprising,” he said.

Rep. José E. Serrano (N.Y.), the ranking Democrat on the commerce, justice and science appropriations subcommittee, called Thompson’s departure “a loss” and added that the bureau needs “robust funding . . . in order to have a successful and accurate operation in 2020. Without strong leadership at the bureau, this vital mission will be imperiled.”

Serrano said he had “no information one way or the other” about whether Thompson was pushed out, but that he “will be exploring this issue further when the Secretary comes to testify before the committee.”

Terri Ann Lowenthal, a former staff director of the House census oversight subcommittee, said she was skeptical that the president would act quickly to nominate a new director. “Considering how many senior administration political appointments remain vacant, I am worried that the nomination could take a while.”