How do humans and T-Rexes co-exist? First off, neither of them considers the other a primary food source. Humans are dinky little creatures that are way more trouble to catch than they're worth. To some predators we smell bad. Meanwhile as a top predator/scavenger, T-Rexes have all the parasites that can be expected and they probably don't taste good either.
Also, if we kill one when we don't want all the meat, that's many tons of meat that will attract a whole lot of scavengers while it rots. You don't want it rotting in your back yard and you don't want those vultures and hyenas hanging out there either.
So it might settle into generally peaceful coexistence. Humans only have to deal with the occasional loser T-Rex that can't get a territory anywhere else and is reduced to trying to take one from us. T-Rexes only have to deal with the occasional loser human who has been thrown out of the tribe and has nowhere else to go, or the occasional loser tribe that can't compete with other tribes for land and has no better choice than compete with dragons.
Human population pressure might eventually leave us encroaching on the big predators, but the slower the population grows the slower that happens. It could look like stability over a human lifespan.
Also, imagine the following scenario -- the T-Rexes are good at preying on 5-ton animals that tend to live in swamps but that come out of the swamps and rummage around. Humans learn by experience that when they have T-Rexes around, the smaller rummagers are not much trouble. But when the T-Rexes are gone the smaller animals are a lot of trouble. They breed in large numbers in the swamp and their surplus comes out and takes our crops and tramples things. If we don't have T-Rexes we need to go into the swamps and cull the things ourselves. So we're better off with T-Rexes.
As for how to drive them away when we need to, that depends a whole lot on how smart they are, and how dedicated they are.
Humans with fire are scary. Would the T-rexes have flammable hair or feathers? That would be enough to scare them off unless they were determined. But if they felt implacable, animals that could put out campfires by stepping on them might not be deterred.
If the big animals were smart, and occasionally determined enough to attack anyway, they could do a lot of damage. If they considered themselves at war, and used smart tactics, and were willing to take a chance of sacrificing themselves for their families and nations, that would be very hard.
If it was something like smart T-Rexes with a bronze age civilization, determined to wipe out humanity before humanity exterminated them, then I can't at all say who would win.