The peaceful rally and march took place in the state capital Munich, about 100 kilometres (60 miles) north of the Alpine venue where Chancellor Angela Merkel is to welcome leaders from the club of rich nations from Sunday.
Authorities estimated the turnout by mid-afternoon at about 34,000, while organisers said 40,000 had turned out in warm, sunny weather on a public holiday in the region.
About 3,000 police kept watch as environmentalists, opposition parties and anti-globalisation activists rallied under the banner “Stop TTIP – Save the Climate – Fight Poverty”. The TTIP or Transatlantic Trade and Investment Partnership is a proposed treaty currently under negotiation between the US and Europe.
In Germany, Europe's largest economy, 43 percent of people think the US-EU trade deal would be “bad” for their country, according to a recent poll.
Hundreds of demonstrations against the planned pact were held across Europe in April.
“We must bring as much pressure as possible to bear,” said Anton Hofreiter of the ecologist Greens, one of the speakers at Thursday's rally.
“No one in the world needs the TTIP treaty – only big companies think it's necessary,” added Klaus Ernst of the far-left Linke party.
One demonstrator scrawled the slogan “Throw your treaty in the garbage” on a rubbish dumpster that he dragged along the march route.
Merkel, who holds the Group of Seven presidency this year, will host the two-day meeting with the leaders of Britain, Canada, France, Italy, Japan and the United States.
A massive police presence is planned at the summit in Elmau Castle, a luxury resort near the Austrian border, with a total force of 25,000 mobilised from around the country.
Demonstrations are planned in and around the town of Garmisch-Partenkirchen, 25 kilometres down the road, and about 300 activists have already set up camp nearby.
“We will use peaceful and creative protests to make sure our demands are heard,” Markus Weber, spokesman for an alliance of non-governmental organisations, told public broadcaster Bayerischer Rundfunk.
The summit is expected to cover international trade, the push for a UN climate accord, public health, poverty reduction and global security crises, among other issues.
Opponents say the G7 has repeatedly failed to take decisive action on the most pressing topics facing people around the world.