He knifed Brian Goldsworthy in the waiting area of the court complex in Swindon, Wiltshire, Adrian Palmer QC, said.
Onlookers grappled with Mr Rachael and he dropped his long- bladed knife - but he picked it up and stabbed Mr Goldsworthy again, Mr Palmer told the jury at Bristol Crown Court.
Mr Goldsworthy, 36, of Upavon Court, Penhill, Swindon, who was dead on arrival at hospital, suffered 12 wounds, some of which severed internal organs and arteries, Mr Palmer said.
Mr Rachael, 34, from Swindon, denied murdering Mr Goldsworthy on 3 December last year, but admitted manslaughter on the grounds of diminished responsibility.
Mr Palmer told the jury that it would have to consider whether Mr Rachael's state of mind was so abnormal it substantially impaired his responsibility for his actions.
Mr Rachael, he said, attacked Mr Goldsworthy with a kitchen knife from the home he shared with Linda Goldsworthy. He hid the weapon in his jeans pocket after tearing the lining to make room for it.
'It was a wholly unprovoked and premeditated attack. His feelings of anger, bitterness, frustration and depression welled up and caused him to explode,' Mr Palmer said.
Mr and Mrs Goldsworthy married in 1977 and had four children. They separated in 1986 and Mrs Goldsworthy formed a relationship with Mr Rachael, who moved in to the family home at Swindon.
They were not married but were known as Paul and Linda Rachael. They had three children - making a total of seven children living with them.
Mr Goldsworthy had started court proceedings to obtain access to his children, and was at the court in connection with the action in December.
Mr Rachael approached Mr Goldsworthy as he was reading court papers, Mr Palmer said.
As he spoke, Mr Rachael repeatedly broke down sobbing in the dock.
Mr Palmer said the jury would hear at least six witnesses who saw the attack, in which Mr Goldsworthy was struck on the chest, neck and face.
Mr Rachael was arrested at the scene, but taken to Princess Margaret Hospital for treatment for a cut to his hand.
Mr Palmer said Mr Rachael's mind was 'working' in the hours leading to the attack. He had picked a knife from the kitchen drawer and deliberately torn his jeans pocket to conceal it.
The defence would submit that Mr Rachael was a man of limited intellect, Mr Palmer said, and would also say he was suffering from a reactive depression at the time of the attack.
The trial was adjourned until today.