When it is said
The priest prays it in the Liturgy of St Mark. It comes in the long intercession for the living, right after the prayers for the sick and for those who have been ill a long time.
Anyone can pray it at home for a prisoner they know, for Christians who suffer for their faith, or for all in prison.
Where it comes from
No author known
The liturgy of Alexandria
The prayer comes from the Liturgy of St Mark, the old liturgy of the Church of Alexandria in Egypt. The early Church historian Eusebius recorded the tradition that Mark founded the first churches of that city. No author of the prayer is named. Its full Greek text survives in a manuscript of the 12th century.
Eusebius, Church History, book 2, translated in Nicene and Post-Nicene Fathers, series 2, vol. 1; F. E. Brightman, Liturgies Eastern and Western, 1896
Words from the psalms
Its praise of God begins with Psalm 146:7-8, where the Lord sets the prisoners free and lifts those who are weighed down. The prayer then calls Him the hope of the hopeless and the help of the helpless, and asks mercy and rest for every Christian in distress.
The Liturgy of St Mark, translated by George Ross Merry, Ante-Nicene Fathers, vol. 7
The Scripture in it
He executes justice for the oppressed and gives food to the hungry. The LORD sets the prisoners free, the LORD opens the eyes of the blind, the LORD lifts those who are weighed down, the LORD loves the righteous.
Bible text: Berean Standard Bible, public domain.
In Greek
Τοὺς ἐν φυλακαῖς ἢ ἐν μετάλλοις ἢ δίκαις ἢ καταδίκαις ἢ ἐν ἐξορίαις
ἢ πικρᾷ δουλείᾳ ἢ φόροις κατεχομένους πάντας ἐλέησον, πάντας ἐλευθέρωσον·
ὅτι σὺ ὁ θεὸς ἡμῶν ὁ λύων τοὺς πεπεδημένους, ὁ ἀνορθῶν τοὺς κατερραγμένους,
ἡ ἐλπὶς τῶν ἀπελπισμένων, ἡ βοήθεια τῶν ἀβοηθήτων,
ἡ ἀνάστασις τῶν πεπτωκότων, ὁ λιμὴν τῶν χειμαζομένων,
ὁ ἔκδικος τῶν καταπονουμένων.
Πάσῃ ψυχῇ χριστιανῇ θλιβομένῃ καὶ περιεχομένῃ
δὸς ἔλεος, δὸς ἄνεσιν, δὸς ἀνάψυξιν.
From F. E. Brightman, Liturgies Eastern and Western (Oxford, 1896), The Liturgy of St Mark, pp. 126-127.