The attack on Pearl Harbor happened during WWII, when Japan was an Axis Power (the main Axis Powers were Germany, Italy, and Japan). This means that Japan was an ally of the Nazis, and therefore an enemy of the Allied Forces.
The Allied Forces were the countries trying to stop Hitler and the Nazis - Great Britain, France, Russia, China, and the United States.
Now, the US wasn't actually fighting in WWII at the time, but Japan was afraid that the country would join soon. So to neutralize the threat, the Japanese tried to destroy the most important American fleets and prevent the Pacific fleet from intervening the war. Ironically, this [the attack on Pearl Harbor] is actually what caused the US to join the Allied Forces.