The nation's foreign trade deficit surged again in April as continuing increases in prices for imported crude oil - and a rush by Americans to buy more fuel-efficient imported cars - wiped out gains of the two previous months.

Commerce Department statistics showed the defict swelled to $2.15 billion in April from $821.3 million in March and $1.3 billion in February. The March deficit had been the smallest in almost two years.

Analysts said the worsening deficit stemmed from two factors:

The sharply higher oil prices and increased U.S. purchases of foreign-made automobiles pushed imports up a sharp 5 percent. American purchases of petroleum and related products soared 9 percent to a seasonally adjusted $4.05 billion.

At the same time, exports declined by 3.9 percent, in part because many shippers were unable to get their goods to the docks during the Teamsters' union strike in April. Economists said exports would bounce back in May.

Analysts said it was too early to tell how much of the trade setback would prove to be long term. Although exports may rebound in May, imports are likely to remain high because of the sharp rise in oil prices.

Continued improvement in the trade deficit late in 1978 and earlier this year had led some analysts to hope for a major reduction in the red-ink figure during 1979. However, oil price increases have altered this outlook.

William A. Cox, the Commerce Department's deputy chief economist, said yesterday it still was "hard to say" how the trade deficit might turn out by the end of this year.

However, Cox noted that even if the deficit were to continue at April's level, overall it still would come in well below last year's record $28.5 billion total.

The increase in U.S. purchases of imported cars accounted for just under half the rise in import levels last month. The bulk of the purchases were from Japan, with some rise in shipments from West Germany as well.

Another 44 percent of the rise in imports was attributed to increased oil purchases. Both the volume and the price of U.S. purchases of foreign oil rose substantially in April.

The April figures brought the cost of overall imports to $16 billion, up $763 million from March's level, while the cost of exports totaled $13.9 billion, down some $569 million from the previous month.

The figures showed the U.S. imported 266.8 million barrels of oil in April compared with 254.3 million in March, at a cost of $4.04 billion, up from $3.7 billion during March.

By comparison, U.S. oil imports a year ago totaled 246.3 million barrels at a cost of $3.3 billion. Crude oil prices hage been rising sharply since last January, in part because of the recent turmoil in Iran.

The $2.15 billion deficit for April was recorded on the department's traditional basis. On another measure, used more widely by other countries, the deficit was $3.17 billion, up from $1.8 billion in March.