To a certain degree, direct armed conflict between the United States was probably inevitable. The United States is a "Pacific" nation. It has a long coastline that runs along the Pacific, and its economic interests have long been tied to the Far East. U.S. possessions in the Pacific, for example, the Hawaiin Islands,Wake Island, the Philippines following the Spanish-American War, Guam, and others were logistical stepping stones enabling the U.S. Navy and merchant shipping to extend the U.S. reach across the ocean. Eventually, that reach come into conflict with expanding Japanese territorial claims throughout the region.
Imperial Japan was militarily and politically aggressive. The Russo-Japanese War of 1905 and Japan's occupation of the Korean Peninsula, Southeast Asia, and Manchuria in mainland China, were all part of the Japanese government's strategy for securing an empire throughout the Pacific. U.S. military forces in the Philippines, Hawaii and the other locations were a potential obstacle to Japanese imperial ambitions. Economic sanctions placed on Japan by the United States in response to the former's brutal occupation policies -- and the "Rape of Nanking" was particularly horrific, with hundreds of thousands of Chinese murdered and untold numbers of women raped -- were seen by Japan as threatening its ability to supply its home islands with oil and other resources.
In an effort at severely degrading the United States' ability to intervene in its plans, Japan drew up plans for attacks on U.S. military forces in the Philippines and Hawaii. The aerial assault on the U.S. Naval Base at Pearl Harbor on December 7, 1941, and the invasion of the Philippines by Japanese troops were the culmination of that planning.
Japan was part of an alliance with Germany. Once war with the United States was initiated on the part of Japan, Germany declared war on the United States, which was already an active participant by virtue of U.S. aid shipments to Britain and, after Germany invaded the Soviet Union in June 1941, to Russia.
The United States was mainly targeted by Japan, though its actions could have made it a target for Germany as well.
Before Pearl Harbor, the United States was deeply involved in helping the British with their shipping. The US was involved, even though it was a neutral country, in escorting convoys across the North Atlantic. Through the Lend-Lease Program, it was providing large amounts of military materiel to the Allies. All of this would have led the Germans to target the US if they had felt that doing so would help them in any way.
It was the Japanese who felt that targeting the US would be helpful. The US was preventing them from taking an empire in East and Southeast Asia. The Japanese believed they had a right to have an empire just like the European countries had. The US, however, feared the rise of Japan and wanted to prevent them from getting that empire. Because the US felt this way, and because the Philippines and Hawaii were bases to forces that could interfere with the Japanese plans, the Japanese targeted the US and attacked Pearl Harbor.