The Andy Murray story is not quite over. However, even a losing comeback to stand comparison with the best of his gilded career should not disguise the reality that his time left on the main stage is not a deal he can negotiate in good faith indefinitely, and he is honest enough to say so.

The world No 23, Roberto Bautista Agut, who arrived at the Australian Open in excellent form, should have buried him inside two hours but Murray dragged him into a dogfight that lasted four hours and nine minutes, before the 30-year-old Spaniard prevailed 6-4, 6-4, 6-7 (5), 6-7 (4), 6-2.

Australian Open: Andy Murray's Melbourne farewell – in pictures Read more

On a pleasant Melbourne Monday evening Murray launched a fightback that gave Bautista Agut repeated cause to believe he would lose to him for a fourth time. However, as Murray’s body faded in inverse proportion to his soaring spirit and the exhortations of the packed Melbourne Court Arena, he had to bow to the inevitable.

The former world No 1 revealed before the match he would have to return to the operating table sooner rather than later to fix his stubbornly ailing hip. Even then the odds on his carrying on would be marginal. He would love to say goodbye at Wimbledon, he said, but he is more likely to have a microphone in his hand than a racket on his next visit.

Nevertheless, with his mother, Judy, and his older brother, Jamie, watching every sweating point Murray flirted with the impossible yet again. Afterwards he said courtside of the match and his reception: “That was incredible. Thank you so much to everyone who came out tonight. Honestly I’ve loved playing here over the years. It’s an amazing place to play tennis. If it was my last match, it was an amazing way to end. I literally gave everything I had. It wasn’t enough tonight, so congratulations to Roberto and his team.

Play Video 2:05 Andy Murray: career highlights from one of Britain's greatest sportsmen – video

“Maybe I’ll see you again. I’ll do everything possible to try. If I want to go again, I’ll need to have a big operation where there are no guarantees I will be able to come back. I will give it my best shot.”

Bautista Agut said: “Andy deserves this atmosphere, deserves all the people who came to watch him. It was an unbelievable match, a really good fight. He is a tough fighter, he gave everything until the last point and I want to congratulate him for all he did for tennis.”

There followed a filmed tribute from several of Murray’s friends and rivals. Roger Federer said: “An amazing career. Congratulations, buddy.” Novak Djokovic said: “Thank you, my friend. All the best. We had quite a journey, from the age of 12.” Rafael Nadal, who has known him since they met as teenagers in Barcelona, was similarly effusive, as were John Isner, Nick Kyrgios, Alexander Zverev and Caroline Wozniacki, who revealed: “You always had the best jokes.”

In the original Scottish play the general comes to grief through hubris, something of which this son of Glasgow could never be accused. Here his honesty was written in every wince and gesture. It was like watching a performance with a sad ending and a familiar narrative, each twist and turn hurling him back from the edge of the stage for one more encore, the place he has been the past two years.

When he could not deliver the dagger after grabbing an early break point, then moments later dumped a backhand, Act I did not offer much promise. Act II drifted further towards a bad place, as Bautista Agut broke early and kept his tennis tidy. Murray, straining in every exchange, failed to find the necessary magic to stay in the longer rallies. The instincts were rock-solid, the racket met the ball with familiar certainty but not as often as needed, and the hip remained stubbornly unreliable.

Bautista Agut stretched him wide and deep, just as Murray used to do in his pomp, when he won three majors, two Olympic gold medals and a Davis Cup. But he was suffering now. He always suffered. Suffering was something he embraced and was a weapon he employed to make opponents kneel before him. Yet this seemed cruel.

It was Bautista Agut who chose when the exchanges ended. After an hour and a half Murray was two sets down and running out of ammunition. Pinned near the baseline, he could no longer find the right angles. His lateral speed was diminished, his balance not always perfect. The inexorable draining of his resources was interrupted by fleeting recreations of his past and he raised a fist each time. Even if it were Federer across the net, the crowd would have been with Murray on this wonderful night.

Own a limited edition Andy Murray print from photographer Tom Jenkins Read more

One could almost hear the final curtain being cranked to descend as Act III got underway. In a quarter of an hour Bautista Agut was up another break, his fourth from five opportunities. Murray waited, playing each ball on merit as if these were the last of his career. Then, against all expectations but his own, he won four points in a row, broke back in the eighth game, held to love and was in front. As the denouement crept closer, Murray discovered his old fighting rhythm. His tormentor got another look on his serve but Murray saved with an inch-perfect backhand – followed by another, then a clinching cross-court forehand.

A couple of cracking ground strokes on both wings in the 10th game got him to within two points of extending the drama. Another hush fell – then the roar ripped around the arena as Murray blasted a backhand for deuce. He got his first set point but found the tape. A drop-shot from deep fell short. A forehand swirled wide. On they went to the tie-break.

Murray had won 194 shootouts in 853 matches, Agut 87 from 400. The Scot, seen having a flutter in the local casino at the weekend, gambled on all-out attack. When he thrashed the winner to seal the set, an expletive slipped from his lips; true to himself, as ever. It was the ninth time he had recovered from two sets down to keep the fight going.

Murray double-faulted for the first time but fought through deuce to level at 2-2 in the fourth. After nearly three hours, at 0-30 down on his serve, he banged his injured right leg hard on the court, as if trying to kickstart an old jalopy. It spluttered into life.

Serving to stay in the set, the match, the championship – and the sport, perhaps – Murray strained all working sinews (and some that maybe were not). He held and, as fireworks from the nearby MCG lit up the night sky, he did so again to force another tie-break, the highlight of which was a checked volley that took him to 5-1 on his way to dragging the bemused Bautista Agut into a deciding set.

Bautista Agut broke for 2-1. From there to the end he steadily dismantled Murray’s resistance, forcing a final tired backhand from him that ballooned just short of the net.