Origin of phrase "barbarians at the gate"

I’ve looked through various quotation sites, assuming it to be from some book or other, but haven’t found a source for this phrase.

This might not be the right answer, but the OP put me in mind of one of my favorite poems:

“Waiting for the Barbarians”

By Constantine Cavafy (1864-1933), translated by Edmund Keeley
What are we waiting for, assembled in the forum?

The barbarians are due here today.
Why isn’t anything happening in the senate?
Why do the senators sit there without legislating?

Because the barbarians are coming today.
What laws can the senators make now?
Once the barbarians are here, they’ll do the legislating.
Why did our emperor get up so early,
and why is he sitting at the city’s main gate
on his throne, in state, wearing the crown?

Because the barbarians are coming today
and the emperor is waiting to receive their leader.
He has even prepared a scroll to give him,
replete with titles, with imposing names.
Why have our two consuls and praetors come out today
wearing their embroidered, their scarlet togas?
Why have they put on bracelets with so many amethysts,
and rings sparkling with magnificent emeralds?
Why are they carrying elegant canes
beautifully worked in silver and gold?

Because the barbarians are coming today
and things like that dazzle the barbarians.
Why don’t our distinguished orators come forward as usual
to make their speeches, say what they have to say?

Because the barbarians are coming today
and they’re bored by rhetoric and public speaking.
Why this sudden restlessness, this confusion?
(How serious people’s faces have become.)
Why are the streets and squares emptying so rapidly,
everyone going home so lost in thought?

Because night has fallen and the barbarians have not come.
And some who have just returned from the border say
there are no barbarians any longer.
And now, what’s going to happen to us without barbarians?
They were, those people, a kind of solution.

I agree. I think a paraphrase of that poem is probably the origin of the phrase “barbarians at the gate.”

There was a book awhile ago (and a movie starring, IIRC, James Garner) about Wall Street power plays and chicanery in the 1980s with that title, which surely spread the phrase much more widely.

WAG here. I wonder if the origin might have something to do with the old tradition that Roman mothers would terrify their brats into submission by warning them that “Hannibal is at the gates”.

I always thought the phrase came from The Decline and Fall of the Roman Empire, but I can’t say why I believe that. Never did finish that book…

The phrase ‘barbarians at the gates’ refers to the Ottoman forces who twice got as far as the gates of Vienna - once in 1529, and once in 1683.