The economy grew at an annual rate of 2.6 percent in the second quarter, the Commerce Department said yesterday, indicating the expansion has enough steam to reach its fifth birthday this fall and become the second-longest in four decades.

The report led Commerce Secretary Malcolm Baldrige to predict that the administration's forecast of 3.2 percent inflation-adjusted growth for all of 1987 "surely" was attainable.

The economy grew at an annualized 4.4 percent rate in the first three months of the year, according to newly revised figures for the gross national product. Its pace for the first half was a 3.5 percent rate.

"The economy's performance during the first half of the year suggests that we can achieve 3 percent growth over four quarters of 1987," Baldrige said. "Conditions are favorable for growth during the second half."

New statistical revisions also released yesterday by Commerce's Bureau of Economic Analysis showed that the economy grew faster in 1984, 1985 and 1986 than had been previously reported. The stronger growth was fueled almost entirely by higher consumer spending, while business investment was lower than earlier thought. {Details on Page D10.}

From April through June, the rate of growth exceeded by nearly one-half a percentage point the general consensus forecast of private economists. Some of those economists were somewhat less optimistic than Baldrige, predicting that some of the factors causing the second-quarter increase were either aberrations or would reverse. However, none expected the economy to contract in the fall.

"When you look at the numbers as a whole, especially in view of what is weak consumer spending, it is a fair report. It is not great," said Lawrence Chimerine, president and chief economist of Wharton Economics. "It does not suggest we have a booming economy, and it suggests we will have a much lower {growth} number in the third quarter."

Growth in the third quarter would give the nation 20 consecutive quarters of an expanding economy. At the end of September, the expansion will have lasted 59 months, and thus surpass the 1975-1980 growth period that has been the second-longest until now.

The longest postwar expansion is the 106-month boom that lasted from 1959 to 1970, when the economy was stimulated by spending on the Vietnam War. But the current period of growth will hold the distinction of being the longest peace-time boom since before World War II.

The second-quarter growth was achieved principally by a $12.8 billion increase in personal spending, which had declined in the first quarter, an $8.2 billion rise in nonresidential fixed investment, which also had fallen in the January-March period, and a rise in net exports of $7.4 billion, smaller than the increase for the previous quarter.

Business additions to inventories were less than they had been in the first quarter, when they accounted for a large part of the economic growth.

An important factor in keeping inventories up, economists pointed out, was a large, and unexplained, increase in farm inventories. Without that rise, annualized GNP growth for the quarter would have been closer to 1.7 percent, according to Donald H. Straszheim, president and chief economist of Merrill Lynch Economics.

"I think there is actually less there than meets the eye," Straszheim said. Other factors that may have contributed only a temporary increase to the rate of growth were federal spending on defense and construction.

The new figures showed a slightly improved inflation picture in the second quarter. Prices for a fixed marketbasket of goods rose at an annual rate of 4.3 percent, compared with 4.5 percent in the first quarter. Baldrige said the "outlook remains favorable, including moderate wage rates, one of the key determinants of inflation."

The annual revisions to the federal GNP figures indicated that the economy grew 2.9 percent in 1986 after adjustment for inflation, rather than the 2.5 percent rate originally reported. In 1985, the growth rate was 3 percent instead of 2.7 percent; in 1984, it was 6.8 percent instead of 6.4 percent.

The stronger growth in the three-year revisions occurred almost entirely on the personal-spending side. Personal consumption expenditures were revised upward by $34.7 billion from the end of 1983 to the end of 1986. Business fixed investment went down by $12 billion.

"In the long run, that is not the mix we want to see," said Donald Ratajczak of the Georgia State University Forecasting Project.

The smaller trade deficit in the second quarter added $7.4 billion to growth and marked the third successive quarterly improvement in the trade deficit, which in 1986 was nearly $170 billion. However, the figures indicated little overall progress in reducing that deficit.

"The trade deficit built up over a period of years," Baldrige said, "We're not going to get it down in one quarter, {but} I think it will pick up faster. The rate of decline will increase as we get toward the end of the year. There is no question ... we have turned the corner on the trade deficit."

Chimerine said the very factors that are reducing the trade deficit -- the decline in the value of the dollar and the relatively small increase in labor costs as companies become more efficient -- will serve to keep consumer incomes and spending weaker than they might have been, thus dragging down that sector of the economy.