The question is not what the EU could do, which is clear, impose its own sanctions/tariffs in response, as it has done e.g. in the aluminium & steel matter and has threatened to do e.g. over cars. The EU has been reluctant to escalate a trade war with the US... but it has shown its red lines in the past; quoting from the aluminium and steel decision:
We did not want to be in this position. However, the unilateral and unjustified decision of the US to impose steel and aluminium tariffs on the EU means that we are left with no other choice. The rules of international trade, which we have developed over the years hand in hand with our American partners, cannot be violated without a reaction from our side.
The real question is whether the EU as a whole is willing to engage in this kind of escalation for what is essentially a project (NS2) that benefits mainly Germany and which is quite opposed in other parts of the EU, e.g. in Poland, which (more or less) itself sanctioned (well, fined) some French firms for participating in NS2 (and not turning over documents related to that). Also Poland sued the EU Commission over the (100%) allocation of gas to [Russian] Gazprom in the OPAL offshoot of NS1... and won. (Germany has appealed this ruling.) So the EU answer to the US sanctions on NS2 may be nothing, but not because no counter-actions would be effective, but because there might not be enough EU consensus for them on issues like NS2 (or Iran).
With respect to Iran, the EU has to balance a stick/carrots routine as well, e.g. this summer they sanctioned Iran over some attacks planned on EU soil against Iranian diaspora/dissidents (which Iran denies it was planning). So it's not obvious the EU is willing to deteriorate their relationship with the US (fraught as it is) over Iran.
The other answer presents the matter as a binary choice of trade-or-no-trade between countries, when there's spectrum of possible actions in a trade dispute. But for NS2 (or Iran) the EU may be unwilling to take any steps because of lack of internal consensus and/or low importance of these matters relative to the relationship with the US.
N.B., in the NS2 case Germany has found a face-saving reason why they won't press with counter-measures:
Despite Berlin's opposition to the legislation, a German government official said on December 21 that Berlin would not respond to the U.S. sanctions with countermeasures.
Peter Beyer, the German government's transatlantic coordinator, said the sanctions targeted private companies, not Germany.
"That is why Germany will not take any countermeasures. If so, this would have to happen at European level anyway, but that won't happen either," Beyer told the dpa news agency.
Some German experts have proposed that Germany impose extra "eco" taxes on gas from fracking, which would hit US LNG companies, but it's unclear how much that would help Germany's case because it imports little LNG from the US anyway. Only about 20-25% of the EU gas terminal capacity is being used nowadays, down from 50% in 2011. However, such taxes could divert (putative) German LNG imports to other countries, e.g. to Qatar, which whom Germany is/was building a closer energy relationship.