Exports increased 7.2 percent to $186.8 billion year-on-year, the General Administration of Customs announced, while imports gained 5.5 percent to $155.2 billion.
China is the world's biggest trading nation in goods. The latest data came as worries earlier this year over its growth outlook have eased following a series of strong indicators in the second quarter, such as industrial production and retail sales.
Gross domestic product (GDP) grew 7.4 percent in the first three months of 2014, weaker than the 7.7 percent in October-December last year and the worst since a similar 7.4 percent expansion in the third quarter of 2012.
China announces second-quarter GDP results on July 16.
Customs spokesman Zheng Yuesheng attributed the improvement in trade in the second quarter to factors including supportive government policies and global economic recovery.
"We expect the pace of growth in trade will be faster in the third quarter than in the second quarter," he told reporters.
"The stabilisation and recovery trend in trade will further consolidate."
Zheng added, however, that "uncertainties" including rising labour costs and the declining position of labour-intensive Chinese products in developed markets were a cause for worry.
"It remains an arduous task to achieve the 7.5 percent target for full-year growth in trade," he said.
June's trade surplus fell short of the median forecast of $36.9 billion in a survey of 21 economists by The Wall Street Journal.
Exports, which accelerated slightly from May's gain of 7.0 percent, fell well short of the median prediction of a 10.0 percent rise.
Imports, which fell 1.6 percent in May, rebounded to surpass the median forecast of a 5.4 percent increase.
China's trade statistics this year have been erratic, with Beijing reporting an unexpected trade deficit of almost $23 billion in February, which authorities blamed on the Lunar New Year holiday season. That was China's first monthly deficit in 11 months.
And in March, China's trade volumes fell dramatically in a development that analysts blamed on the continued impact of fake over-reporting of exports seen in early 2013.
For the first six months of this year, China's trade surplus declined 4.4 percent to $102.86 billion, as exports rose 0.9 percent to $1.06 trillion and imports gained 1.5 percent to $960 billion, Customs said.
China's leaders say they want to transform the country's growth model to make consumer spending and other forms of private demand the key drivers of the economy.
The new model would steer it away from an over-reliance on huge and often wasteful investment projects that have underpinned decades of past expansion.
Such a makeover is expected to result in slower but more sustainable growth in the long run.