But retail sales fell for a fifth straight month and at a somewhat faster pace, a worrying sign for private consumption, which accounts for more than half of the world's third-largest economy.
Monday's data underscored the fragility of an economy that suffered a record 27.8% contraction in the April-June quarter as the pandemic took a heavy toll on both domestic and external demand.
While analysts believe the economy has bottomed out after lockdowns were lifted in late May, they say any rebound will be modest amid worries about a second wave of infections.
"The bounce-back in factory output will run its course in August and we expect a pullback in production in October-December," said Toru Suehiro, senior market economist at Mizuho Securities.
"Factory output will fluctuate from now on to settle in at about 90% of the pre-coronavirus crisis level," he said.
Ministry of Economy, Trade and Industry (METI) data showed Japan's industrial output grew 8.0% in July from the previous month, versus economists' median estimate of a 5.8% gain and following a 1.9% increase in June.
The growth rate was the fastest on record going back to 1978, the government said.
It was also the second straight month of gains after having hit its lowest level in May since the global financial crisis.
Manufacturers surveyed by METI expect output to increase 4.0% in August and grow 1.9% in September.
METI officials said industrial output will continue to improve but activity would remain below pre-crisis levels for some time. The officials said they were closely watching the impact of a resurgence in coronavirus infections.
Compared with a year earlier, output was down 16.1%.
Highlighting weak consumer demand, however, retail sales fell 2.8% year-on-year in July, worse than a 1.7% drop seen by economists in a Reuters poll and following a 1.3% drop in June, separate METI data showed on Monday.
Declines in car demand dragged down overall retail sales, and department stores and supermarkets suffered from sluggish consumer activity amid a surge in new COVID-19 cases.
Clothing demand also suffered, while oil product sales fell reflecting declines in crude oil prices, the data showed.
On a seasonally-adjusted basis, retail sales fell 3.3% month-on-month in July, posting the first drop in three months.
By Tetsushi Kajimoto