For the Japanese, Midway was a desperation move. Admiral Yamamoto had warned the Japanese government that if they went ahead with the Pearl Harbor attack, Japan would enjoy unprecedented victories for a few months, but none afterward. The Pearl Harbor raid was a spectacular success, and lead to the Japanese conquest of much of the Pacific. It's only real failure was the US carriers weren't at Pearl during the raid and thus survived. Yamamoto knew this, and he felt he needed to land an all destroying blow that would destroy America's carriers in the hopes that such action would destroy the American carriers and force America to surrender.
And while Yamamoto may have been desperate to get a crushing victory, for many other Japanese officers, their own arrogance would doom them at Midway. The Japanese believed the Americans to be weak and cowardly, fat and lazy, not the noble and invincible Samurai. In the immediate aftermath of Pearl Harbor, America never "stood and fought" against the Japanese attacks. Where it could, the US pulled the bulk of its forces back to buy time. These Japanese victories convinced the Japanese that they were invincible and that nothing could stop them. As a result, certain aspects of discipline failed them at Midway.
And then the battle came. Found through the efforts of American PBY Cattalinas and the Submarine USS Nautilus, the Japanese fleet was quickly targeted. The first strike came from B-17s based on Midway itself. Despite being sold to the US Army Air Corps as a long range maritime patrol aircraft, the raid failed to hit a single ship in the Japanese fleet. The failure of this raid partially convinced Nagomo that the US fleet would be defending Pearl Harbor and Hawaii, not Midway and launched his aircraft to strike Midway Island with a reserve with torpedoes in case the US fleet was found.
Nagomo was then met with the failure of some of his own equipment. He had sent out search planes, in case the US fleet was around, but one of the last search planes he had couldn't be launched on time, which bought the US fleet time. By this time the Hornet, Enterprise, and Yorktown came within range to launch their own aircraft, and they did so.
Much of the next part of the battle occurs simultaneously. Japanese bombers raid the American base on Midway, doing only minor damage and failing to destroy the airfield as another wave of B-17s prepare to sortie. At sea, the American torpedo planes reach the Japanese fleet. Because of both distance and the fact that many of their fighter escorts had gotten lost and failed to find the Japanese fleet, the American torpedo planes are met with a wall of Japanese anti-aircraft fire and swarming Zero fighters. The torpedo bombers fail to hit a single Japanese ship.
Following this, the Japanese fleet is again attacked by B-17s from Midway. Again the heavy bombers fail to hit a single ship, but they do present a problem for Nagomo. Should he focus on pounding Midway and wait for the American fleet to be found, or should he leave Midway and focus on the US fleet. His movements are incredibly indecisive until he finally decides to target the island base, forcing the Japanese crews to take the planes intended to attack the US fleet, if it is found, to be taken below and rearmed to attack Midway. At the same time another wave of American torpedo bombers comes in.
Again the torpedo planes are cut to pieces, but after long defensive patrols, the Zeros protecting the fleet needed to land and refuel before they could either defend the carriers or escort the next raid on Midway. It was decided to allow the Zeros to land and refuel. And at this time, American SBD Dauntless Dive Bombers finally arrived on the scene. With most Japanese aircraft either at low altitudes because of the torpedo planes or refueling, these dive bombers are given rather easy targets in the Japanese fleet carriers. The dive bombers then sink 3 of Japan's four carriers with one Japanese carrier also torpedoed by the submarine Nautilus.
By this time, the Japanese finally find the US fleet and launch the first retaliatory strike against them. Japanese aircraft hit the carrier Yorktown and seem to do extensive damage to the ship. However, the damage control teams on the Yorktown manage to put the fires out and keep the ship battle worthy, despite its damage. When the second raid on the US fleet arrives, the Japanese attack the Yorktown again, thinking it is a different ship. Again the attack does serious damage, but the damage control teams manage to keep the ship floating. However, by this time Yorktown's fate is sealed. It is torpedoed by a Japanese submarine and the Americans decide to scuttle the ship. Meanwhile, dive bombers from the Enterprise finally find the last Japanese fleet carrier, and sink it essentially ending the battle.