The United States, aided by a dominant second leg from Michael Phelps, earned the gold medal in the men's 4x100-meter freestyle relay, avenging their painful loss to France in 2012. Team USA, which consisted of Phelps, Caeleb Dressel, Ryan Held and Nathan Adrian, beat France by 0.61 seconds to take back the gold.

With the win, Phelps extends his records to 23 Olympic medals, 19 golds.

Adrian, who was the anchor for the U.S. relay team, earned his fourth Olympic gold medal. He, along with Phelps, were the two returnees from the 2012 relay team that finished with the silver. Dressel and Held each are first-time gold medalists, as both made their Olympic debuts in Rio.

The relay, with France considered the favorites as defending Olympic champions coming in, had multiple dramatic points early, but the U.S. left little doubt late.

After Dressel kept it extremely close on the first leg, the U.S. trailed France by .02 seconds. Phelps was next in the water and the U.S. still trailed France by 0.13 seconds after the first 50 meters of the second leg. That was when the most decorated athlete in Olympic history made his big move and opened up a lead of 1.03 seconds over Australia, which briefly overtook the French team.

The U.S. never trailed again as Held helped his team maintain a 0.47 second advantage over the French after the third leg. Adrian brought it home, holding off a late push by France to finish with an official time of 3:09:92. Australia finished with the bronze.

Michael Phelps and Caeleb Dressel celebrate Team USA's gold medal win in the 4x100m relay. USATSI

Before Sunday, it was not clear if Phelps would definitely swim the relay. Reports soon surfaced that he was expected to be in and the veteran made no secret that he desired a spot in this event. The 31-year-old Olympic legend made the most of the opportunity.

Four of Phelps' 23 medals have come in the 4x100-meter freestyle, an event that has historically been owned by American men. This was only his second gold medal in this event, however, having also won in the dramatic relay in 2008 at Beijing. He also has a bronze from 2004 and 2012's silver.

"We wanted to bring that relay back to American soil," Phelps told NBC after the race. "We had a sour taste in our mouth from 2012. I'm glad that's back on our soil."

In what is probably (maybe?) his final Olympics, Phelps got a big win in an event that clearly meant a lot to him and he had a big hand in it.

While Phelps will get the headlines, each of Team USA's swimmers had a big hand in this win. That includes the quartet that made sure the U.S. qualified for the final in one of the most exciting events in swimming.

Held was the only American swimmer in the finals to have also participated in Sunday morning's preliminary heat. He, along with Blake Pieroni, Jimmy Feigen and Anthony Ervin helped put the U.S. in position to win gold with their preliminary-round performance.

According to USA Swimming, the gold in the men's relay represented the 300th Olympic medal earned by American men's swimmers.