By Michael Holden

LONDON (Reuters) - The man accused of murdering British lawmaker (MP) Jo Cox in June was heard saying "this is for Britain" during an attack that was motivated by politics or ideology, a London jury was told at the opening of his trial on Monday.

Thomas Mair, 53, is charged with Cox' murder, which took place a week before Britain's referendum on EU membership and led to the suspension of campaigning for several days. A plea of not guilty was recorded on his behalf at an earlier hearing after he stayed silent when asked to enter his plea.

Cox, a 41-year-old mother of two young children, was shot and stabbed on the street in the town of Birstall, part of her electoral district in northern England, as she arrived for an advice session with local residents at a library.

Mair was arrested nearby shortly after the killing. He said words to the effect of "it's me" and described himself to police as a political activist, prosecutor Richard Whittam told London's Old Bailey court.

Police later found publications at Mair's home about white supremacists, Nazi Germany, shootings and assassinations. He had also accessed websites on topics such as the Ku Klux Klan and the Waffen SS in the days and weeks before the killing.

"Thomas Mair clearly held views that provided him with a motive, utterly misplaced of course, to kill. He killed her because she was an MP who did not share his views," Whittam said, adding that Mair had researched Cox on the Internet.

A former aid worker before she was elected to parliament, Cox was an ardent supporter of staying in the EU. She was shot three times and stabbed 15 times in what Whittam described as a "dynamic, fast-moving and shocking" scene.

He told the court several witnesses reported hearing gun shots and seeing Mair wielding what one of them described as a large steak knife with a jagged blade. He was heard repeating the words "Britain first".

Whittam said Cox's aide Fazila Aswat, who was with Cox at the time of the murder, had heard him say "Britain first, this is for Britain, Britain will always come first".

"DEATH TO TRAITORS"

Whittam did not draw a direct link between the referendum and the murder, nor did he elaborate on the meaning of "Britain first" or Mair's other words.

Mair, a Birstall resident, is also charged with causing grievous bodily harm to 77-year-old Bernard Carter-Kenny, who tried to help Cox during the attack, and possession of a firearm and a dagger.

Carter-Kenny risked his own life and was stabbed with the same knife Mair used to attack Cox, Whittam said.

A few days before the murder, Mair had looked up Cox's Twitter page as well as a Wikipedia entry on Ian Gow, the last British member of parliament to have been killed before Cox.

Gow was killed in 1990 by the Irish Republican Army (IRA), which was fighting for Northern Ireland to split from the United Kingdom and become part of the Republic of Ireland. An IRA bomb exploded under Gow's car at his home.

Balding with a gray goatee beard and wearing a dark blue suit and black tie, Mair sat silently in the dock flanked by three security guards as Whittam delivered his statement.

At the first court hearing shortly after his arrest, Mair had said his name was "death to traitors, freedom for Britain". The case, due to last two weeks, is being treated as a terrorism matter.

(Writing by Estelle Shirbon; editing by Stephen Addison)