The nation's economy grew at a rapid 8.7 percent annual rate in the second quarter of this year, considerably faster than first estimated and enough to confirm that this recovery so far is in line with those of the average since World War II, the government said yesterday.

The latest Gross National Product (GNP) figures showed that the United States has "buried the 1981-'82 recession," Commerce Secretary Malcolm Baldrige said. He added that "nearly all of the 3 percent decline in real GNP during the recession was recouped during the first half of the year," although he agreed that unemployment still is much higher than before the recession began.

Consumer spending fueled the rapid growth during the March to June period, with spending on automobiles and on services particularly strong, the Commerce Department said.

Its revised figure for growth in the first quarter of this year was little changed at a 2.6 percent annual rate.

Baldrige cautioned that the pace of recovery likely will slow in the last six months of 1983 from the nearly 9 percent second-quarter rate. Two-thirds of that rise was due to a slowdown in inventory liquidation between the first two quarters of this year. The inventory swing is "kind of a one-time effect," the Commerce secretary told reporters. While he predicted some further boost to the economy from a switch to inventory building during the present quarter, he said it likely would have a much smaller impact on the economy.

Growth in the first half of the year as a whole measured 5.6 percent on an annual rate basis.

Martin Feldstein, chairman of the Council of Economic Advisers, said yesterday that "of course, expansion at the recent rate cannot be expected to continue for more than a few quarters."

The economy is likely to grow at a pace of 5 percent or 6 percent for the remaining two quarters of 1983, rather than the 8 percent to 9 percent rate notched up between March and June, Baldrige said. If growth turns out to be any higher, then the administration's latest economic forecast--released only last month--will prove to be too low.

The White House has twice revised upward its projections for growth this year, with its latest forecast looking for a rise in GNP of 5.5 percent between the fourth quarter of last year and the end of this year.

The 8.7 percent annual rate still is only a preliminary number, and may be revised again later. The annual rate increase, measured in inflation-adjusted 1972 dollars, was equivalent to $31.3 billion for the quarter.

The strength of the recovery in recent months has led to some concern that fast-rising output could exacerbate inflation, with some economists cautioning that the economy is growing too strongly.

Baldrige rejected these concerns yesterday, saying "the underlying trend of economic growth is not excessive." He told reporters that "we do not have to worry about inflation problems" this year or for most of next.

Treasury Secretary Donald T. Regan also said that the speed of the recovery does not constitute "over-heating."

However, both they and Feldstein warned that unless Congress cuts spending to reduce the projected budget deficits, rising interest rates in later years could abort the recovery. Baldrige put the blame for large deficits on Congress and not on the administration's unwillingness to raise taxes.

Inflation, as measured by the GNP fixed-weight price index, accelerated to 5.2 percent in the second quarter from 3.4 percent in the first three months of this year, yesterday's release said. The change was due to fuel prices, which dropped early in the year and then swung up in the second quarter, Baldrige said.

One of the weaker components of GNP was the trade sector. Exports decreased by $3.1 billion at an annual rate, measured in 1972 dollars, while imports climbed by $7.2 billion. The trade sector constituted a drag of $10.3 billion on the economy in the second quarter of the year, compared to a decline in real net exports of $2.5 billion in the first three months of the year.