The U.S. economy grew at a healthy pace in the second quarter, slowing by less the economists had expected from earlier in the year amid multiple headwinds, including weaker global demand, higher mortgage rates, and uncertainties over trade policy.

Gross domestic product rose at a 2.1 percent annual rate from April through June, the Commerce Department reported Friday. Gross domestic product is a measure of all the goods and services produced in the U.S. after adjustments for seasonality and inflation.

Consumer spending was a source of strength for the economy, expanding at a 4.3 percent rate. Earlier in the year, consumer spending had slumped to a 0.9 percent growth rate. But the increase in consumer spending was offset by a decline in business investment. So-called nonresidential fixed investment fell at a 0.6 percent rate, down from a rise of 4.4 percent in the first quarter.

The U.S. economy has officially entered the longest expansion in its history, with GDP rising for 121 consecutive months. That is longer than the previous 120-month record set in the decade between 1991 to 2001.

Although the second quarter’s growth rate was slower than 3.1 percent in the first three months in the years, at 2.1 percent it was better than economists expected. According to Econoday, the median forecast was for 1.9 percent, with a range of 1.6 to 2.2 percent.

Even at the slower pace of the second quarter, the economy is still performing beyond what Federal Reserve economists see as its long-range potential. In March, the median projection of Fed officials was for 2.1 percent growth in 2019. If the second-quarter’s 2.1 percent pace holds up in subsequent revisions, the economy is almost certain to grow by more than forecast.