Both reasons are true
We are trying to finally stop Iran from becoming a nuclear state, which would be catastropic because they would happily nuke Israel and then Israel would nuke them back and that would be the least terrible of possible outcomes even if other nations didn't get involved and start launching their nukes. Just a localized nuclear exchange would kill millions of people instantly, irradiate large sections of the Middle East, and scatter radioactive fallout over neighboring nations, Europe, and Russia
We are also trying to contain China, and being able to control and throttle their energy imports is a very important step towards that goal. This is especially true since we know Chairman Pooh has directed the PLA to be ready to invade Taiwan by 2027. No one knows the actual state of PLA readiness for a full amphibious assault of the island but everyone knows that tanks, ships, and jets don't run on batteries. They run on petroleum, and if we control the petrol, we control China's ability to invade Taiwan
There's a lot of geopolitics going into the recent decisions to depose Maduro over in Venezuela and then attack Iran. Trump is trying to solve multiple problems here, Iran getting nukes is one but the other bigger one is China threatening to invade Taiwan in addition to trying to bully and dominate all of its neighbors in East Asia