In a showdown between the world's best player and doubles pair, Croatia's top-ranked twosome beat a Serbia team led by Novak Djokovic to send their country into the Davis Cup final.
Croatia will seek its third Davis Cup on Sunday against the winner of Saturday's other semifinal between Russia and Germany.
Djokovic pulled Serbia level at 1-1 by beating Marin Cilic 6-4, 6-2 before he stepped back on the Madrid Arena's indoor hard court for the decider. But Mektic's and Pavic's well-honed teamwork proved too much for the 20-time Grand Slam winner.
"We went out there believing we could do it, but we always knew that it was going to be the toughest rubber if it came down to doubles, playing the best team in the world," Djokovic said. "They know each other so well. When one crosses, the other knows where the other one will be. We singles players just play it back into the middle. They always make you hit the perfect shot."
Serbia had won the previous two Davis Cup meetings with Croatia since they became independent nations following the breakup of Yugoslavia.
Djokovic did what he could early, hitting five aces to save five break points to keep Serbia in the first set.
But when Krajinovic needed to hold serve to force a first-set tiebreaker, he twice returned into the net before Mektic broke his serve by smashing a forehand past the Serbs.
Ahead a set, the Croatia partners were ruthlessly efficient the rest of the way, breaking Serbia's serve twice more. It was over when Djokovic sent his last shot sailing long and wide.
"We really showed great spirt from the start," Metkic said. "Everyone on the team gave it 110%. What can I say about our second guy winning some great matches."
Gojo, Croatia's No. 2, got them going with a win that Troicki said was the "crucial" point of the tie given the Croats' strength in doubles.
The 279th-ranked Gojo outplayed Lajovic after the Serb rallied from 4-1 down to take the first set. Gojo broke Lajovic's serve five times to give his team the early advantage.
Djokovic then topped Cilic, going up a set after he saved four break points. He then cruised through the second set, stroking winners that thrilled the pavilion packed with fans of both nations.
Concluding a spectacular season that included three Grand Slam victories, Djokovic said Serbia must learn from the loss if it hopes to win the Davis Cup again.
"As much as it hurts, these moments are usually the best to develop and grow into a better person and player, and hopefully we will learn from what happened this year," Djokovic said. "We definitely need to have a doubles team playing constantly together or it will be an Everest for us to climb."