The basics are:
FCC compliance (Title 47, Part 15B) and proof of testing is required for the advertising or sale of products in the uS or Canada containing any switchmode power supply, switching amplifier (class D), any circuits clocked at over 9kHz including DSP and microcontrollers. IF the product contains any form of RF broadcast, including Bluetooth, analog or digital wireless links, it must also be tested to Part 15C which generally includes a different certification and licensing procedure. Canada generally follows the FCC guidelines under ISED. USA and Canada require conducted and radiated emissions testing. The product must comply before the FCC mark may be placed on the product.
Compliance for the EU is a little more involved, the requirements are generally similar (not identical) to the FCC conducted and radiated emissions testing but include additional tests for immunity, including Electrostatic Discharge, Radiated Immunity, Electrical Fast Transients, Conducted Immunity, Power Frequency Magnetic Fields and Voltage Dips + Interruptions. The product must comply before the CE mark may be placed on the product.
Safety in the US and EU are generally similar, though the AC mains voltages are obviously different. The standards are all integrated into a single IEC standard (62368) with distinctions for the US and Canada which are managed and referred to as UL and cUL 62368. The reason for this is that dielectric strength requirements and working voltage calculations are different due to the different mains voltage. These standards are hundreds of pages long, are very complex and costly to test to. Generally a couple of each product is damaged during the testing process. There are also national differences for different countries within the EU as well as for CENELEC countries that are signatories to IEC.
To place the UL or CE compliance mark on a product, the manufacturer must have the product tested by a Nationally Recognized Testing Lab, AND it must pass. A technical file must be maintained that includes all documentation of the product as well as copies of the test reports, certificates, critical components data, inspection reports, Engineering Change Orders, importer of record for each shipment, etc. When products are exported, it's normal for the customs office of the importing country to verify that the documents are in place and valid. Do products slip through, sure, but quality companies will follow the rules. The penalties for going around the rules IF YOU GET CAUGHT are substantial.
Here's an interesting story that looks at just EMC compliance for a pedal product (attached):