TOKYO — Japan’s economy grew more strongly than expected in the second quarter, extending the longest streak of uninterrupted growth in 11 years, government data showed on Monday.

And the really good news: Much of the growth was local.

Japan’s government has been trying to spur the economy with a stimulus program known as Abenomics, after Prime Minister Shinzo Abe. The strategy has helped Japan’s exporters but has done little to increase domestic income or spending.

That may be changing.

Spending by Japanese consumers and businesses contributed more to the latest expansion than trade with the rest of the world did, the data showed, in a positive sign for the outlook of the world’s third largest economy, after the United States and China.

What Happened?

Japanese gross domestic product increased by 4 percent in annualized terms in the three months through June, the government’s Cabinet Office said in a preliminary estimate on Monday. The economy has now expanded for six consecutive quarters, the first time it has gone that long without a contraction since the 2005-6 period.

The pace of expansion also accelerated from the previous quarter, and was stronger than economists had expected. Analysts surveyed by Reuters had forecast a growth rate of 2.5 percent.

Where Did the Growth Come From?

From Japan, unusually. Foreign trade had done most of the heavy lifting since the start of the expansion, aided by a broadly recovering global economy and the weak yen. Abenomics calls for Japan’s central bank to inject more money into the financial system. That weakens the country’s currency, which makes Japanese cars, electronics and other products more competitive when sold abroad. Multinationals like Toyota have profited, but the tactic has failed to significantly bolster consumer spending at home.

Exports are still crucial to the economy. But Japanese are buying even more goods from abroad: A surge in imports last quarter meant that trade was a net drag on G.D.P.

By contrast, the domestic side of the economy jolted to life. Consumer spending grew by 3.7 percent in annualized terms, the data showed, while business investment expanded by nearly 10 percent — a sign that companies are becoming more optimistic that the good times will last.

Is the Government Helping?

Not all of the domestic growth came from private citizens and businesses. Mr. Abe announced a major government spending program a year ago, and the data suggest the money is beginning to find its way from account books to the real economy. Public investment grew at a 22 percent pace.

Japan has the largest public debt in the world, relative to the size of its economy, but ultralow interest rates let the government borrow cheaply. The central bank is, in effect, underwriting public spending by buying up government bonds — an arrangement criticized as reckless by fiscal conservatives, but welcomed by others who say Japan needs the pump-priming.