Harry Duffy, 25, from Elmwod Terrace, Derry and James Anthony Kennedy, 24, from Glenside Park in the city admitted breaking into Christ Church on 12 September 2017.
The BBC reports that Derry Crown Court heard they smashed through a 19th century stained glass window.
Human excrement was smeared inside the church and on pages torn from a bible.
Judge Philip Babington said some of the damage was both shocking and disgusting.
He said there was no doubt in his mind that the effects of alcohol and drugs caused both Kennedy and Duffy to behave in the way they did.
Duffy and Kennedy were jailed for two years and eight months.
Both will serve a portion of the sentence on licence.
Both men had no previous convictions, the court was told.
Duffy and Kennedy also admitted burgling the church and stealing items including a crystal decanter, a surplice and a set of reader’s robes.
They also admitted damaging furnishings and fittings inside the church, including the church organ.
Judge Babington said their behaviour was “quite disgraceful and aggravated as it was by taking place at and within a place of worship”.
He added: “It caused very great sadness and upset to the members of Christ Church.
“It was also completely senseless, destroying as it did a 19th Century stained glass window and causing over £40,000 worth of damage to a musical instrument, the organ.”
When arrested, the court was told, Duffy admitted being in the church and defecating inside the boiler room. He apologised for what he had done.
The court heard that Kennedy was arrested in his home. Police found Facebook searches about the incident and about the church on his phone.
Judge Babington added: “Although at first glance one might wonder if there was some religious or sectarian aspect to this offending, I am quite satisfied that this is not the case.”
In a statement, Archdeacon Robert Miller, the parish’s rector and Rev Katie McAteer, the pastoral director, said they were thankful to the judge for the “sensitive manner in which he has dealt with what has, for our parishioners, been a most distressing case”.
“We take no pleasure from the significant custodial sentences handed down to the two offenders.
“We do feel, however, that actions have consequences and that all of us should be accountable for our actions before the law.”