Neither player was giving anything up in a tense encounter on No.3 Court, with Bedene having to wait until the 14th game of the fifth set to make the breakthrough and clinch a 6-7 (5-7) 7-6 (8-6) 6-7 (7-9) 7-6 (9-7) 8-6 victory.
It was a first at the All England Club, as no match in Wimbledon history had ever previously reached 6-6 in the fifth set without a break of serve.
Karlovic, seeded 21st, was unable to take any of the eight break points that came his way, all of which arrived in sets he let slip.
For Bedene the chances were more limited. He had a pair of opportunities to move up in game two of the third set and game nine of the fourth before finally bringing the match to a close after four hours and 25 minutes.
The Brit leapt into the air when his shot down the line was placed out of Karlovic's reach on match point, with Damir Dzumhur awaiting in the next round.
Meanwhile, Andy Murray and Rafael Nadal commenced their Wimbledon campaigns with straight-sets victories.
Defending champion Murray comfortably saw off Alexander Bublik 6-1 6-4 6-2 on Centre Court, while Rafael Nadal cruised into the second round courtesy of a 6-1 6-3 6-2 triumph over John Millman.
Murray has struggled for form through much of 2017, while Nadal was playing at Wimbledon for the first time in two years but neither showed any signs of rustiness.
Nadal delighted an appreciative Court One crowd with a string of impressive shots – none better than a drop shot with enough spin on it to make Shane Warne proud up against Aussie Millman.
Murray naturally had the Centre Court gathering at his back, who remained in high spirits despite a couple of rain delays - it is Wimbledon after all!