Spain, who won their first title at Eurobasket 2009 in Poland, blew away Slovenia 86-64 while Macedonia, playing in only their third tournament as an independent nation, stunned hosts Lithuania 67-65.
The two will meet in Friday's opening semi-final while the winners of the Russia v Serbia and France v Greece quarter-finals, scheduled for Thursday, will clash in the other semi.
Macedonia entered the 24-team tournament in Lithuania with slim hopes of advancing from their preliminary pool, but instead shocked one more heralded rival after another to send their colourful band of supporters into raptures.
Lithuania, the 2003 champions, were one of the favourites for a podium finish but will now have to work hard to secure even an Olympic qualifying berth available to just two of the four losing quarter-finalists.
American point-guard Lester Bo McCalebb again inspired the Macedonians, who now have a 7-2 record in the tournament, with a game-high 23 points but it was Vlado Ilijevski who emerged as the match-winner in a dramatic climax.
Ilievski capitalised on a turnover with 11 seconds remaining and slotted an audacious three-pointer as the Lithuanians watched in disbelief before failing to score on their last possession.
"I've never had emotions as strong as these in my entire career, we were written off as complete underdogs before the tournament and now we have the whole nation behind us," Macedonia centre Pero Antic said.
"We have silenced our critics and 14,000 home fans in Kaunas, we dedicate this victory to the Macedonian people after playing our hearts out for our country," he added.
Thousands of fans thronged the central square in Macedonia's capital Skopje to celebrate after watching the game on giant video screens, sporting national flags and team shirts.
Unlike Macedonia, fellow former Yugoslavs Slovenia never looked capable of springing an upset against classy Spain who produced their best performance of the tournament to stay on course for a second successive title.
Having weathered an early seven-point led by the Slovenians, Spain quickly regained their composure as centre Marc Gasol dominated in the paint and Juan Carlos Navarro found his shooting range.
The Spaniards led 35-31 at halftime and opened the third quarter with a 19-2 run which effectively sealed the contest, with Navarro scoring nine points in that rally.
He finished with a game-high 26 points, Pau Gasol poured in 19 and collected 16 rebounds while Jose Luis Calderon added nine points for the Spaniards, who had 15 rebounds and seven assists more than their rivals.
Slovenia, who have never enjoyed a podium finish as an independent nation, will now enter the 5th-8th place playoff along with the losers of the other three quarter-finals.
The winners and runners-up of Eurobasket 2011 will qualify automatically for next year's Olympics in London along with hosts Britain, while the next four teams in line will enter an inter-continental, 12-team play-off for another three berths.