Plainclothes police watched as Mohamed Muhiyadin emerged from the flat in Alhambra Road, Southsea on January 8.
Portsmouth Crown Court heard how officers watched the 20-year-old, from Shirland Road, London, repeatedly go in and out of the flat after selling drugs to a known addict.
Officers arrested Muhiyadin, who had six £10 notes on him, and burst into the flat he was seen leaving and entering.
Inside, Lukas Sakalas, 20, was hiding in the bathroom trying to shut the door on police and was seen with his left hand behind his back attempting to hide crack cocaine and heroin in his body.
The court heard CS gas was sprayed in his face and Sakalas dropped to the floor but still tried to conceal the item.
A large hunting knife was found inside the flat, but that was not subject to any separate charge.
When arrested officers found 41 wraps of heroin weighing a total of 7.01g worth £310 to £620, and 72 wraps of crack cocaine weighing 7.14g with a street value of £720.
Garage worker Sakalas, who had been drawn into dealing by people who knew him while he was buying cannabis, has a previous conviction for possession of a bladed article, breaching an eight-week suspended jail term imposed in May last year.
Muhiyadin, who had been forced to work for dealers to pay back a drug debt, has a previous conviction for robbery and was jailed for 21 months. He was released in November last year.
Jailing Sakalas for 20 months and Muhiyadin for 24 months, judge William Ashworth said: ‘On January 8 Mr Muhiyadin you were seen dealing drugs in Alhambra Road and the police went back to the address and found Mr Sakalas, 31 wraps of heroin, 72 wraps of crack cocaine - total value of £1,000 to £1,300.
‘There was cling film and troublingly a hunting knife in the lounge.
‘You were both dealing in Portsmouth as part of a county lines style dealing that’s prevalent in the area.’