In the poem, broadcast in March 2016, satirist Jan Böhmermann accused Erdogan of bestiality and watching child porn, while gleefully admitting he was flouting legal limits to free speech as a deliberate provocation.
The Hamburg civil court, upholding a ruling from last May, barred Böhmermann from repeating lengthy passages of the poem, objecting to 18 of its 24 lines.
It ruled that the claimant "does not have to accept insults or verbal abuse", even if the offensive passages were clearly not intended to be taken seriously.
The Turkish leader had sought a complete ban on the poem.
Böhmermann's performance sparked a row that badly soured Berlin-Ankara relations at a time when Turkey was vital to EU plans to stop the mass flow of migrants from the Middle East and Africa into the bloc, especially to Germany.
Erdogan had also sought to bring a criminal case against Böhmermann under a rarely enforced lese majeste law, but German prosecutors rejected the claim as they found the satire so exaggerated it could not be taken seriously.
German lawmakers voted last month to strike the 19th-century lese majeste law, which threatened jail terms for insulting foreign heads of state, from Germany's legal code.
The comedian's poem came in reaction to Ankara's decision to summon Germany's ambassador over another satire, a song broadcast on German TV which had lampooned Erdogan in far tamer language.