But he recovered to convert in the shoot-out as Portugal scraped through to set up a blockbuster clash with France in the quarter-finals.
Slovenia battled valiantly to keep Portugal at bay, with Jan Oblak making a stunning save to keep out Ronaldo’s penalty after Diogo Jota was fouled.
However, Ronaldo, Bruno Fernandes and Bernardo Silva all scored in the shoot-out and Slovenia’s trio missed, sending the Selecao through in heart-stopping fashion.
“First it was sadness and then it was joy, that’s what football gives you, inexplicable moments, a bit of everything,” said Ronaldo.
“I didn’t make a single mistake this year and when I needed something the most, Oblak saved it.
“Slovenia spent the whole game defending and when that happens, it all becomes difficult.”
Ronaldo, 39, is still without a goal at the tournament in four appearances, having scored in the five previous editions of the Euros.
The Euro 2016 winners dominated the ball and created their first chance after 12 minutes when Silva’s inviting cross just evaded Ronaldo and Fernandes could not turn home at the far post.
Slovenia, playing in their first ever knock-out match at a major competition, maintained their defensive shape well and limited Portugal’s opportunities.
Former Real Madrid striker Ronaldo directed a soft header at his old nemesis, Atletico Madrid keeper Oblak, under vital pressure from Vanja Drkusic.
The Slovenian defender was booked moments later for bringing down the surging Rafael Leao as he charged towards Oblak’s goal.
Ronaldo smashed the free-kick narrowly over the bar with the goalkeeper at full stretch.
Slovenia produced their first effort on target just before half-time when RB Leipzig striker Benjamin Sesko fired at Costa from the edge of the box.
Portugal’s holding midfielder Joao Palhinha hit the outside of the post with a low drive, the final kick of the first half, after more good work by the menacing Leao.
Ronaldo forced a solid stop by Oblak with another venomous free-kick early in the second half as the Al-Nassr forward tried in vain to break down Slovenia’s defensive wall.
Matjaz Kek’s side had a golden chance to take the lead on a rare burst forward, but Sesko dragged wide after beating the oldest player in the competition’s history, 41-year-old Pepe, for pace.
Portugal captain Ronaldo thumped yet another free-kick over the crossbar with 20 minutes remaining and Oblak denied him with two minutes to go when he was through on the left.
Oblak thwarts Ronaldo
The pace dipped in extra-time and the first period was uneventful, until the 103rd minute when Jota barged into the area and went down over Drkusic’s leg for a penalty.
Ronaldo fired it hard to Oblak’s left but the goalkeeper produced a stunning save to deny him, tipping his effort against the post and out.
In half-time of extra-time, Ronaldo was in tears after his miss, and Portugal fans sang his name to try to raise his shattered morale.
Slovenia missed another huge opening of their own when Pepe gave the ball away with a loose pass and Sesko stole it to race through on goal.
The forward fired too close to Costa who produced an excellent save with his leg, forcing a penalty shoot-out — Slovenia’s first ever.
Slovenia went first and substitute Josip Ilicic’s effort was brilliantly saved by Costa.
Ronaldo buried his kick and asked for forgiveness from the fans behind the goal for his extra-time miss, before Costa saved Slovenia’s second from Jure Balkovec.
The brilliant Costa made a third consecutive penalty save from Benjamin Verbic after Fernandes converted and Silva won it as he sent Oblak the wrong way.
© Agence France-Presse
Photo: Justin Setterfield/Getty Images