Can a US pilot fly a German D-xxxx aircraft in Germany? Can a pilot with a US FAA certificate and a proper rating legally fly a D-xxx German-registered aircraft within Germany? How about the rest of the EU? Does it matter which type of aircraft? I'm most interested in gliders, but the question is more general.
No. A US licenced pilot can not fly a German registered aircraft in Germany. 

Generally you must always have a pilot licence issued by the state that the aircraft is registered in.

Obtaining a licence for that country can be relatively easy based on the fact you already have a licence from another country, but you will need a new licence or some kind of documentation issued by the governing country. 

There is an FAA rule that allows a US licenced pilot to fly a foreign registered aircraft the USA, but I think this is rather unique as I believe no other country allows this.