Portugal's Iuri Leitao and Rui Oliveira prevailed in one of the most chaotic Olympic madisons ever witnessed, taking advantage of a late crash from Italy's Simone Consonni to steal a lap inside 20 laps to go and rocket into the gold medal position.
Denmark's Michael Mørkøv and and Niklas Larsen, who took a lap at the midpoint, won the bronze.
"The last 25 laps were supposed to be full gas, because we were predicting that everybody was really, really fatigued, so we knew if we could just keep it up, they will open on our wheel, and we just had to keep going," Leitao said. "And we were sure that we could break them. And in the end, we were right.
"I knew the points were really close. We won the penultimate sprint, and then we took the lap. We were just two points ahead. We were a little bit afraid of the Italians because they are really fast on the sprint, and also the Denmark guys, but I tried to save my golden bullet to the final. We had a plan for me to do the last sprint, and in the end, we had the result we wanted."
For Oliveira, winning itself was a new experience and standing on the world's biggest stage atop the podium, even more so.
"I've never won a single race in my life. To be Olympic champion as my first win is, well, I still don't know if this is all real, really. That's insane," Oliveira said.
Italy had been leading over Denmark after taking five sprints and 20 points for a lap in the first half of the 200-lap race, but a botched change left Consonni on the deck and his partner Elia Viviani having to continue racing, waiting for Consonni to rejoin.
That left the team vulnerable to the attack from Portugal, who took the points with 20 laps to go then kept pushing, gaining the lap just after taking the penultimate sprint.
Then, the Portuguese duo poured on the gas in the final laps, winning the final sprint - worth double the points - to deny the Italians the win. The Danes held on comfortably to give the soon-to-be-retired Mørkøv another Olympic bronze medal to go with the gold earned in the same event in Tokyo.
"We did a strong race from the start to the finish. I tried to collect some points. We picked a very good moment to take a lap, we got ahead of the race, and in the Madison it is often about being very consistent.
"Tokyo gold was the highlight of my career, but to be here at the age of 39, finishing my career this year winning a medal with a relatively new partner, Niklas, also makes me very proud. Until the race was finished, we were still fighting."
How it unfolded
Austria went on the attack from the gun to take a lap and won the first sprint to move into the lead with 25, however, they would later blow up and get dropped, losing three laps before getting pulled from the race.
As they were on the attack, a rider from France came underneath the Germans Roger Kluge and Theo Reinhardt during their exchange, causing a crash between the Germans and New Zealand. Luckily the riders were quickly back up and riding.
The Netherlands and Italy got on the board early with sprint points before eventual gold medalist Leitao went on the attack before sprint 4 to take the five points on the line.
The Portuguese were in the lead as Spain's experienced pair Sebastian Mora and Alberto Torres got on the board on sprint 5, but Italy won the next sprint and then soon went on the attack to claim the next sprint.
New Zealand put themselves further into contention taking sprint 7, but then Italy counterattacked and claimed both sprint 8 and 9 before lapping the field to move comfortably into the race lead.
Denmark counter-attacked after taking second in sprint 9 and mopping up the points on sprint 10 to move into the silver medal position with Spain and New Zealand tied for third.
Germany picked up the 11th sprint before Japan's pair Imamura Shunsuke and Kuboki Kazushige went on the attack and quickly took a lap, picking up sprint 12 along the way to get ahead of the Kiwis and move into third behind Italy and Denmark.
The next action came when the Czech duo Denis Rugovac and Jan Vones attacked to lap the field and they succeeded with 46 laps to go.
The brutal pace soon began to cause disastrous mistakes, however. The Netherlands went on the attack, chased by New Zealand but as Jan Willem van Schip came past Great Britain's Ollie Wood, who was riding low on the track in relief, Van Schip hit Wood with his head and caused the Briton to fall.
The Netherlands won sprint 16 but couldn't get the lap, nor could New Zealand, as chaos continued to unfold.
A dramatic crash from Belgium and Spain came in the mad dash for the closing points before Portugal began their late scramble to climb into the medals.
The Portuguese won sprint 17 and went on the attack, taking out sprints 18 and 19 just as they latched onto what the officials would deem a second group.
Awarded the five points for the penultimate sprint, the Portuguese team was two points behind Italy when, in a freak touch of wheels while exchanging, Consonni came down, leaving Viviani to fend for himself.
When they finally regrouped, it was too late and Leitao stole away to take the final sprint and the gold medal, leaving Viviani in tears as he saw the victory vanish up the track.