The new law, which must still be approved by the Bundesrat upper house, also outlaws symbols of the Kurdistan Workers’ Party (PKK), listed as a terrorist group by Turkey and its Western allies.
Previously, only symbols of organisations banned by Germany had been prohibited.
The move comes after several violent and anti-Semitic pro-Palestinian rallies in Germany during the escalation of the Middle East conflict in May.
Thorsten Frei, a lawmaker for Chancellor Angela Merkel’s CDU, told Die Welt newspaper last week that the government wanted to ban the Hamas flag in response to the demonstrations.
“We do not want the flags of terrorist organisations to be waved on German soil,” he said, adding that a ban would send “a clear signal to our Jewish citizens”.
Germany saw several demonstrations during 11 days of fighting between Israel and Hamas in May, with protesters shouting anti-Semitic slogans, burning Israeli flags and damaging the entrance to a synagogue with stones.
At one protest in Berlin, 59 people were arrested and dozens of police officers injured as protesters threw stones, bottles and fireworks.
The Central Council of Jews in Germany said it had received “a torrent of the most vile anti-Semitic insults” on social media.
Council president Josef Schuster urged the police to take a hard line against anti-Semitism and said the events had been “reminiscent of the darkest times in German history”.
Interior Minister Horst Seehofer said Germany would crack down hard on anyone found to be spreading “anti-Semitic hatred”.
“We will not tolerate Israeli flags burning on German soil and Jewish institutions being attacked,” he told the Bild am Sonntag newspaper.