RIO DE JANEIRO (AP) — Allyson Felix and LaShawn Merritt are savvy track stars who’ve been around long enough to know that not everything always goes to plan.

Over the final 30 minutes of Saturday’s topsy-turvy night at the Olympic track, both Americans came away with prizes they’d been wishing for all along.

Those prizes were both golds from the 4×400 relay teams, and the United States exited the final night of action at Olympic Stadium with 31 medals — the most it has taken in a non-boycotted Olympics since 1956, when both the world and track were very different places.

“People are at home watching — watching 2012, watching 2008,” said Felix, 30, who wrapped up her fourth Olympics and now has nine total medals. “And when they get their opportunity, they’re seizing the moment.”

One of those moments looked like it might belong to 41-year-old Bernard Lagat in the 5,000 meters. He actually finished fifth, but two runners ahead of him, including American Paul Chelimo , were disqualified for interference and Lagat briefly moved to third. “Really?” he exclaimed when told about it during post-race interviews.

A review ensued, Chelimo was reinstated to silver and Lagat dropped back to fifth — a bummer for the elder statesman of the U.S. track team, but some sort of sign for the team: Even when it lost, it won.

“I thought it was a joke,” Chelimo said of the moment when he was told his silver was gone. “I couldn’t believe. Now I’m really happy. I got reinstated. It’s the best feeling ever.”

All those reviews and appeals made for a strange scene as the program came to a close. Mo Farah, Chelimo and Hagos Gebrhiwet marched to the podium to receive their medals nearly an hour after the evening’s final race, in front of only a few thousand stragglers in the stands. It was Farah’s second straight 5,000-10,000 Olympic double, putting an exclamation point on the games for his home country, Britain.

The medal ceremony was wacky. But the night’s biggest surprise came from Matthew Centrowitz, who shocked the field in a slow 1,500-meter final and became the first American to win gold in the “metric mile” since 1908. His time was 3 minutes, 50 seconds.

“Doing my victory lap, I literally kept screaming to everyone I know, ‘Are you kidding me?'” Centrowitz said.

Felix spent a lot of the week saying the same thing — and not in a good way.

This has been an adjust-on-the-fly year for America’s best-known track star — her failure to make the team for the 200 meters, her jaw-dropping silver-medal moment when a diving sprinter from the Bahamas beat her in the 400, and more. But on back-to-back nights, she took relay gold, starting with the 4×100 on Friday. The wins gave her gold medals No. 5 and 6 — a record for a woman on the Olympic track.

In the 4×400, she ran a 49.66-second anchor lap. Over the second and third laps, Americans Natasha Hastings and Phyllis Francis held big leads, only to have them dwindle as they legged out their final meters.

Felix took the green baton about two steps ahead of Jamaica’s Novelene Williams-Mills, and slowly, steadily expanded it for a total time of 3:19.06 and a 1.28-second win. Yes, the United States may have relay problems — see, the men’s 4×100, which flamed out again the night before — but this certainly isn’t one of them. This race has gone to American teams six straight times.

The smile she flashed as she crossed the line and waved the baton said what words could not: Thank goodness, it’s finally over.

“The toughest, without a doubt,” Felix said of her 2016. “This year, you make plans and want everything to go according to schedule. Nothing went according to schedule.”

Merritt might have said the same. He was caught in the tail wind of South African Wayde van Nierkerk’s world-record 400 run earlier in the week and settled for bronze. Then, Merritt was a bit player in the Usain Bolt going-away party, finishing sixth in the 200 — a race he considered pure gravy.

But Bolt was long gone — having stopped by the track quickly to receive gold medal No. 9 and take a selfie with Farah — and South Africa had left the building, too.

As Felix had done minutes earlier, Merritt took a narrow lead and opened it way up. This relay gold goes with those he took in both the 4×400 relay and the 400 flat in 2008. He was injured and on the sideline in 2012.

“The 200 was just extra for me, there was no training regimen for it,” the 30-year-old Merritt said. “If I would’ve medaled, I would’ve been grateful. But we really wanted to win this 4×4. It didn’t go the way the guys wanted it four years ago, so we knew how important it was.”

It wasn’t all perfect for the red, white and blue.

High jumpers Chaunte Lowe, a mother of three who finally felt ready for her Olympic moment, and Vashti Cunningham, daughter of former NFL quarterback Randall, finished fourth and 13th in a contest taken by Ruth Beitia of Spain.

In the night’s other finals, Thomas Rohler of Germany won the javelin and South Africa’s Caster Semenya took the women’s 800 meters in a result that surprised nobody.

That the Americans are leaving with the most medals is no shock, either. They’ve done it at every Olympic track meet since 1992.

The numbers may not have shocked anyone. Some of the names, and where they ended up on the results list, certainly did.

“I would have been really happy with a silver,” Centrowitz said. “And coming away with gold is unbelievable.”