WASHINGTON—The U.S. trade gap expanded modestly in May, perhaps finding its level after a port disruption on the West Coast caused a turbulent spring.

The trade deficit increased by 2.9% to a seasonally adjusted $41.87 billion in May, the Commerce Department said Tuesday. Economists surveyed by The Wall Street Journal had forecast a deficit of $42.5 billion.

In May, imports fell 0.1% to $230.47 billion. Exports decreased 0.8% from April to $188.6 billion.

Trade figures had been extremely volatile in recent months due to a now-resolved labor dispute at West Coast ports. Revised figures show a $40.7 billion gap in April, compared with a $50.57 billion deficit in March.

The three-month moving average for the deficit was $44.38 billion in May, up 2.8% from the same period a year earlier.

The latest data may provide a better picture of U.S.'s trade position, and how it is influenced by a strong dollar and lower demand for foreign oil.

The dollar has gained value against many other currencies this year. That makes U.S.-made products more expensive for overseas consumers.

Nonpetroleum exports declined 4.5% in May compared with a year earlier.

Likewise, the strong dollar makes imports cheaper for U.S. consumers. Outside of petroleum, the dollar value of imports has risen 1.9% from a year earlier, despite the cheaper prices.

Imports of vehicles and parts reached a record in May, but imports of industrial supplies, a category that include crude oil, was the lowest since August 2009.

Another factor influencing the overall trade gap: The petroleum deficit has narrowed sharply in recent years as domestic oil production surged. The trade deficit for petroleum products was $5.78 billion in May, the lowest reading since February 2002.

The petroleum deficit narrowed despite the average price for a barrel of crude oil rising in May above $50 for the first time since January.

International trade provided a boost to the early part of the economic recovery, but it has been a drag on output in recent quarters. Exports add to gross domestic product, while imports subtract.

In the first quarter, trade cut 1.9 percentage points from GDP, which contracted at a 0.2% annual pace, the Commerce Department said last month. Trade has weighed on economic output in four the previous five quarters.

Some economists expect the drag not to be as deep in the second quarter, though tepid overseas demand has been one obstacle for American companies. The Greek debt crisis is causing turmoil for the European economy. At the same time, growth in China and other Asian economies has slowed recently.

Federal Reserve officials have an eye on the global economy as they consider raising the central bank's benchmark interest rate from near zero, where it has held since December 2008. Following a June policy meeting, officials said they would take into account "international developments" as well as inflation and labor-market data as part of their interest-rate decision.

"The United States has very limited direct exposure to Greece," Fed Chairwoman Janet Yellen said last month. "But to the extent that there are impacts on the euro-area economy or on global financial markets, there would undoubtedly be spillovers to the United States that would affect our outlook as well."

U.S. exports to the EU decreased 0.8% in May from April, on a nonseasonally adjusted basis. Exports to the EU are up 1% through the first five months of the year, compared with the same period a year earlier. Imports from the European countries fell 2.8% in May from April, but are up 1.2% through the first five months of the year versus 2014.

In May, the U.S. recorded its first trade monthly surplus with Canada in records back to 1990.

Write to Eric Morath at eric.morath@wsj.com and Jeffrey Sparshott at jeffrey.sparshott@wsj.com

Subscribe to WSJ: http://online.wsj.com?mod=djnwires