The fall compared with a Reuters poll forecast for a decline of 17.8% in exports, and against June's 23.17% slide.
The ministry still expects exports to fall by 8%-9% this year, Pimchanok Vonkorpon, head of the ministry's Trade Policy and Strategy Office, told a briefing.
"Overall exports recovered with a check-mark shape. We are hoping there will not be more lockdowns in other countries which will disrupt trade," she said.
Shipments of cars and car parts declined 30.9% in July from a year earlier after June's 43.2% plunge. Gold exports rose 37% year-on-year after a 86% fall in the previous month.
Exports to most markets were lower in July, with ones to China down 2.7% year-on-year, but those to the United States jumped 17.8%, helped by electronics and rubber products, the ministry said.
While a rise in exports to the United States, accounting for 14.5% of the total in January-July, the largest share, could be scrutinised over trading practices, several shipments, including semi-conductors, were from U.S. companies in Thailand, Pimchanok said.
Last month, the central bank said Thailand had not intervened in the baht for any competitive trade advantage following a media report that Thailand could be added to a U.S. watch list for currency manipulation.
In January-July, exports, a key driver of Thai growth, contracted 7.72% from a year earlier, while imports fell 14.69%.
Thailand recorded a trade surplus of $3.34 billion in July and $14 billion in the first seven months of this year.
(Editing by Ed Davies)
By Kitiphong Thaichareon and Orathai Sriring