John McIntyre, 51, attacked 39-year-old Alison Lyons when she found him standing in her bedroom at the flat in Greenock, Inverclyde, in August.
He also stabbed Ms Lyons' work-mate, 20-year-old Matthew Power.
At the High Court in Glasgow, McIntyre was jailed after he admitted assaulting the pair to the danger of their life.
Judge Lord Turnbull jailed McIntyre for what he called "serious conduct".
The court heard how McIntyre slipped into the flat while Ms Lyons and two guests were asleep.
When she awoke and realised he was there, she asked him what he was doing.
McIntyre, from Greenock, then stabbed her twice in the stomach with a vegetable knife taken from her kitchen drawer.
He then climbed on top of Mr Power and struck him with the blade before feeling from the flat.
Ms Lyons suffered a punctured bowel and her gall bladder had to be eventually removed.
Mr Power suffered wounds to his chest and wrist. Medics discovered the knife had come within millimetres of his heart.
McIntyre later handed himself into police having been identified as the attacker.
A man who stabbed his former partner after he turned up uninvited to her flat-warming party has been jailed for five years and four months.