Overall leader Simon Yates takes Tour of Switzerland victory
Almeida started the final time trial, 15.7km uphill from the headquarters of the International Cycling Union in Aigle to the resort of Villars-sur-Ollon, 31 seconds behind overall leader Yates.
The Portuguese rider won in 33 minutes 23 seconds, but was only nine seconds ahead of the Briton at the line.
The UAE pair had taken the top two places on each of the three previous stages. Each finished with two stage victories.
Yates confirmed his return to form after suffering concussion in a crash at the Tour UAE in February. He collected his 28th victory as a professional and his first in a major stage race.
"It's definitely up there," said Yates at the finish. "About two days to go, I wasn't sure if I could do it.
"I just couldn't accelerate, I was already over the limit so I just tried to hold the pace and thankfully it was enough.
"I'm still out of breath because it was such a hard climb, but one thing I had in the back of my mind for a while was the 2019 Tirreno-Adriatico where I lost the TT on the last day by one second and this had lived rent-free in my head for many years so it's finally good to win a race and win it with a TT.
"To win any big bike race is a big privilege and to share the podium with Joao as well, he's a special teammate."
Yates was third in the last Tour de France and will be team leader Tadej Pogacar's luxury lieutenant in this year's edition.
Almeida, who acted as pacemaker when Yates won stage five, should also be part of the Tour de France team.
"I'm really happy with the time trial stage victory, I think my first TT victory except nationals so that's pretty good," said Almeida.
"At the start of the day, I knew it was quite impossible to win the GC against Adam."
Defending champion, Mattias Skjelmose, Dane with Lidl-Trek, clawed back one place in the overall standings and moved onto the podium, ahead of Colombian Egan Bernal of Ineos.