A man accused of murdering a 21-year-old with learning difficulties persuaded his wife to give him an alibi, a trial has heard.
Dean Shorney was described as having 'the mind of a child'
Wayne Royston, 35, from Bargoed, Rhymney Valley, denies stabbing Dean Shorney to death in a town park.
Cardiff Crown Court was told Mr Royston denied to the police that he had been in the park or ever met Dean Shorney.
However, he had told his wife he had a fight and asked her to say he was at home the night of April 18 this year.
Mr Shorney, a popular figure in the Bargoed community who has been described as having the "mind of a child", suffered 38 stab wounds and his throat had been cut from ear to ear.
Police arrested Mr Royston two days after the murder and interviewed him 19 times over three days, prosecutor Peter Murphy QC told the jury.
The court previously heard the defendant was diagnosed as having a dangerous, severe personality disorder. Doctors, who passed on concerns to the police, considered his condition untreatable.
Two years later, Mr Royston told doctors he was "having homicidal thoughts all the time" and that a month before the killing, he said those thoughts had worsened.
The prosecution also said that he had run out of his medication the day before the stabbing.
During the first police interviews, Mr Royston said that after returning home from the pub before the killing, he had spent the rest of the evening in the house.
A statement from his wife backed up this account.
Police discovered an array of weapons including two samurai swords, a machete and an axe among other items at Mr Royston's house.
They also found a pair of jeans at the bottom of a wash basket which had a bloodstain matching a sample of DNA from Dean Shorney.
"The chances of any of those stains coming from someone other than Dean Shorney are one in a billion," said Mr Murphy told the court.
Mr Shorney's body was found at a park in his home town of Bargoed
He added that a knife from a set which Mr Royston's wife had hidden from him because of his mental health problems had never been recovered.
He said: "This killing, we suggest, matches the manner and nature of the killing which he fantasises about carrying out.
"Wayne Royston cut Dean's throat and stabbed him a further 37 times. He knew and knows what he is doing and that is that he murdered Dean Shorney."
The following day his wife Emma gave another statement in which she revealed she had argued with the defendant about money on the night of the killing before he left the house for a walk, Mr Murphy said.
After he returned, he told his wife he had been in a fight with another man and had left him where he could be found.
"The next day after she had learned about the murder, she asked him if he had done it. He said no. She couldn't believe he was responsible for the killing," said Mr Murphy.
The jury was told tracker dogs picked up the trail which showed Wayne Royston had been in the park in the same area where Dean Shorney's body was found.
Mr Royston then changed his story, telling officers he had been in the park that night and had come across the body of Mr Shorney, who looked injured.
He told detectives he was worried his psychiatric history would implicate him and so had not said anything before.
The trial continues.