District Judge Zoe Passfield told criminal Josh Creasy, 25, she had been close to putting him behind bars.
But she instead suspended for 18 months the immediate one-year sentence she had planned to impose on Creasy, of Quarry Street, New Silksworth.
At South Tyneside Magistrates’ Court, she told him that it had been input from the Probation Service that stopped him being jailed.
One person taken to hospital after North East Air Ambulance lands at Roker Beach
Two taken to hospital after collision closes A690 near Ramside Hall Hotel
Troubled woman caused £30,000 damage by setting fire to her Gentoo home in Sunderland
Fresh bid to convert former council offices in Hetton into flats
Careless driving, no insurance and fare-dodging – the latest Sunderland court cases
The agency told her a previous prison term had failed to deter Creasy from offending and only a community-based punishment was left to try.
Judge Passfield told Creasy: “Until two minutes ago, you were going to be serving 12 months in prison.
“The reason you are not going to be serving that is because the Probation Service are willing to give you one last chance.
“If you let them down, you go to prison. You couldn’t have been closer to a prison sentence today. If we see you back here, that’s what will happen.”
The court heard Creasy and another man burgled the Cherry Tree pub in Ayton, Washington, on Wednesday, May 18, stealing cash from machines.
On the same day, they raided a Chinese takeaway in Grangetown, Sunderland, taking an estimated £400, prosecutor Paul Anderson said.
He revealed Creasy assaulted the police officer in Sunderland on Sunday, February 20, and caused £200 of damage to South Shields bus station on Thursday, May 12.
Of the pub break-in, Mr Anderson said: “The person in the flat above was terrified by what was going on below.”
Describing the PC attack, he added: “The police are called to an incident where there’s a suggestion some cars may be damaged.
“They find the defendant lying on the ground between two parked cars.
“He was arrested but became aggressive. He tried to headbutt an officer and had to be restrained on the ground.
“He then spat on the left side of the officer’s face, and he lashed out.”
Creasy pleaded guilty to two burglaries, assault by beating of an emergency worker and causing criminal damage.
The court heard he has 64 previous convictions and was jailed last August for assaulting police, and had three other convictions for attacking emergency workers.
Jason Smith, defending, said: “With his offending behaviour, he’s fallen off the wagon, for want of a better description.
“He was taken into care during his adolescence. His work ethic is exceptional, he regularly works.
“When he’s in full-time and gainful employment, we don’t hear from him. When not working, he gets led astray and influenced by others.”
Judge Passfield jailed Creasy for 26 weeks for assault, 52 weeks for each burglary and 28 days for criminal damage, all suspended and to run concurrently.
Creasy, described by the Probation Service as being immature for his age, must complete 35 rehabilitation days and the Thinking Skills programme.
He must also do 100 hours of unpaid work and pay compensation of £100 the police officer and both burglary victims.
There were no court costs.
The court heard Creasy’s burglary co-accused had also received a suspended sentence.