Scotland goalkeeper Craig Gordon made his first appearance in 13 months as Hearts scrambled into the fifth round of the Scottish Gas Scottish Cup following a stoppage-time Frankie Kent winner away to cinch League Two side Spartans.

The Jambos looked set for a smooth afternoon against their Edinburgh counterparts when Kenneth Vargas opened the scoring in the 13th minute but a stunning equaliser from James Craigen had the part-time hosts dreaming of a famous result.

Centre-back Kent, however, picked the perfect moment to score his first goal for the Jambos to secure a 2-1 victory and spare his team-mates and manager Steven Naismith from what would have been stinging criticism.

Gordon, playing his first match since suffering a career-threatening double leg-break on Christmas Eve of 2022, was handed the captaincy on his return, with Lawrence Shankland – skipper in the goalkeeper’s absence – missing out through injury.

Hearts’ new right-back Dexter Lembikisa, who joined on loan from Wolves earlier this month, was named among the substitutes and would come on in the 59th minute.

Gordon had such a comfortable opening to proceedings that by the time he first touched the ball his team had already moved into a 13th-minute lead through Vargas.

The Costa Rican forward was perfectly stationed at the back post to nod in from six yards out following an inswinging cross from the left by Alan Forrest.

Hearts dominated possession early on but Gordon was called into action in the 21st minute when he acrobatically tipped over a powerful, swerving 20-yard strike from Callum Booth.

The Jambos remained on top, however, and Forrest saw a couple of low shots from the edge of the box in quick succession saved by Spartans keeper Blair Carswell, whose father Allan was the Hearts goalkeeping coach when the Jambos last won the Scottish Cup 12 years ago.

At the other end, a promising attack brought a rare sight of goal for Spartans but Jamie Dishington shot high over from 25 yards out.

Vargas looked set to double his tally just before the break when he got on the end of a lovely clipped cross from Alex Cochrane in a central position 10 yards out but the forward was denied by an excellent save from Carswell.

The Spartans keeper then produced another impressive stop to keep out Vargas’s shot from the edge of the box early in the second half.

Kent then headed wide from Jorge Grant’s corner before Cochrane saw a shot from distance saved by the outstanding Carswell.

Hearts were made to rue their inability to find a second goal when Craigen volleyed home a magnificent equaliser from the edge of the box, with Gordon left rooted to the spot as the ball flew into his top right-hand corner.

With Spartans generally holding firm in the face of Hearts’ pressure in the closing stages, the tie looked all set for extra time until Kent nodded in Cochrane’s corner.