WASHINGTON — America’s trade deficit narrowed more than forecast in June to the smallest in almost four years as a reduced dependence on foreign oil helped give a boost to the world’s largest economy.

The gap shrank 22.4 percent to $34.2 billion, the lowest since October 2009, from a revised $44.1 billion in May that was less than previously estimated, the Commerce Department reported Tuesday in Washington. The shortfall was smaller than all estimates in a Bloomberg survey. Another report showed job openings rose during the same month.

Record exports and a drop in purchases of goods made abroad prompted economists at firms such as JPMorgan Chase to increase their tracking estimates for second-quarter growth. At the same time, a projected pickup in domestic demand indicates it may be difficult for the deficit to improve further.

“This is exceptionally good news,” said Millan Mulraine, director of U.S. rates research at TD Securities USA in New York. “This could suggest GDP could be increased by as much as 1 percent.” Still, the level of the trade deficit is “unlikely to be sustained given the weak global growth.”

Figures Tuesday from the Labor Department showed job openings rose in June to the highest level in five years even as employers hired the fewest workers so far this year, adding to evidence of an uneven improvement in the labor market.

The number of positions waiting to be filled rose by 29,000 to 3.94 million, the most since May 2008, from a revised 3.91 million in May, the Labor Department said.

“It’s not all good news,” said Jonathan Basile, an economist at Credit Suisse in New York. Still, “if you’re looking for forward guidance, you hang your hat on the job openings number, and that looks good.”

Figures from Europe showed economies in the region are beginning to stabilize. German factory orders increased in June by the most in eight months and Britain’s industrial sector rebounded.

The median forecast in a Bloomberg survey of 72 economists called for a $43.5 billion U.S. trade deficit. Estimates ranged from shortfalls of $38 billion to $48.3 billion. The Commerce Department initially reported a $45 billion gap for May.

Exports increased 2.2 percent to $191.2 billion, boosted by sales of petroleum products and capital goods including engines and telecommunications equipment. The value of services provided to foreign customers by American companies climbed to a record.

Refineries in the U.S. imported less petroleum, and demand for consumer goods made overseas declined, helping drive down the value of all imports by 2.5 percent to $225.4 billion.

Increased domestic energy production is helping reduce America’s reliance of foreign crude oil. The import figures reflected 234.3 million barrels of oil, down from 240.5 million barrels in the prior month. The value of crude oil purchases fell to $22.7 billion from $23.3 billion in the prior month.

“There’s something to be said on the role of America’s growing energy independence,” said Tim Quinlan, an economist with Wells Fargo Securities in Charlotte, N.C. Wells Fargo economists said Wednesday trade figures may add 0.8 percentage point to growth.

After eliminating the influence of prices, the trade deficit narrowed to $43.1 billion from $51.9 billion.

The economy expanded at a 1.7 percent annualized rate from April through June after a 1.1 percent pace in the first quarter, the Commerce Department said July 31. The initial estimate for gross domestic product reflected a 0.8 percentage point drag from trade, which was the most in almost three years.

“It now looks like net exports were a neutral factor for second-quarter growth,” JPMorgan economist Daniel Silver said in an email to clients. The firm raised its tracking estimate for second-quarter GDP to 2.3 percent from the previously reported 1.7 percent.

Economic growth is projected to average 2.5 percent at an annualize pace in the second half of the year, up from 1.4 percent in the first six months, according to the median forecast in a Bloomberg survey of 68 economists from July 5 to July 10.

Recent reports underscore the projections for an improvement over the remainder of the year. Service industries expanded in July at the fastest pace in five months, the Institute for Supply Management reported yesterday, with construction companies, retailers and financial firms reporting a pickup in business. That report followed data last week that showed manufacturing advanced at the fastest rate in more than two years.

Automakers are on pace for their best showing in six years as job gains boost confidence and consumers replace older vehicles. Cars and light trucks sold at a 15.6 million annualized rate in July and 15.9 million the prior month, the strongest back-to-back readings since late 2007, according to figures from Ward’s Automotive Group.

The trade gap with China, the world’s second-biggest economy, narrowed to $26.6 billion from $27.9 billion, today’s report showed. The trade deficit with the European Union, Canada and Mexico also shrank.

For some companies such as Eaton Corp., which makes electrical equipment for buildings, demand is being restrained by federal budget cuts and weaker overseas markets. Dublin-based Eaton last week lowered its 2013 growth forecast for U.S. nonresidential construction to 2 percent to 3 percent from an earlier projection of 4 percent to 5 percent at the beginning of the year.

“We think the global economy is trending up slowly,” Sandy Cutler, chairman and chief executive officer at Eaton, said on an Aug. 2 conference call. “The U.S. is plodding. Europe may be at a bottom, but we see little prospect for a lot of vigor in a prospective recovery at this point. We do not see a major catalyst for a change in the second half of this year.”