One eyewitness told the BBC they heard her attacker shout "put Britain first" at least twice beforehand.
A 52-year-old man was arrested near Market Street, Birstall, West Yorkshire Police said. The MP holds a weekly advice surgery nearby.
The MP was taken by ambulance to Leeds General Infirmary, where armed police were stationed outside, but the MP's death was confirmed at police headquarters in Wakefield.
Police said they were not looking for anyone else in connection with the attack, and were not willing to comment on any possible motive.
Mrs Cox is the first sitting British MP to be killed since 1990, when Ian Gow was the last in a string of politicians to die at the hands of Northern Irish terror groups.
Her husband Brendan Cox said she believed in a better world, "and fought for it every day of her life".
"She would have wanted two things above all else to happen now, one that our precious children are bathed in love and two, that we all unite to fight against the hatred that killed her. Hate doesn't have a creed, race or religion, it is poisonous.
"Jo would have no regrets about her life, she lived every day of it to the full."
He also posted a picture on Twitter of his wife standing beside the Thames.
Vote Leave and Remain have both suspended campaigning in the EU referendum in light of the attack.
Labour leader Jeremy Corbyn said the country would be "in shock at the horrific murder", describing the MP as a "much loved colleague".
He added: "Jo died doing her public duty at the heart of our democracy, listening to and representing the people she was elected to serve.
"In the coming days, there will be questions to answer about how and why she died.
"But for now all our thoughts are with Jo's husband Brendan and their two young children. They will grow up without their mum, but can be immensely proud of what she did, what she achieved and what she stood for."
New Zealand MP Phil Twyford worked with Mrs Cox, and said he was shocked and gutted.
Mr Twyford hired her for a job with Oxfam in Brussels - and said she was a fabulous colleague and full of heart.
He said she was feisty, independent minded, and not afraid to take on the leadership of her own party on some issues.
Mr Twyford said Mrs Cox referred to herself as a proud Yorkshire lass, and was very proud of her working class upbringing.
'People screaming'
Cafe owner Clarke Rothwell, who witnessed the attack, said he heard a "loud popping noise that sounded like a balloon burst - a loud balloon".
"When I looked round there's a man stood there in his 50s with a white baseball cap on and a jacket with a gun, an old fashioned looking gun in his hand," he said.
"He shot this lady once and then he shot her again, he fell to the floor, leant over shot her once more in the face area.
"Somebody tried to grab him, wrestling with him and then he wielded a knife, like a hunting knife, just started lunging at her with a knife half a dozen times. People were screaming and running from the area".
Eyewitness Hithem Ben Abdallah, said the 41-year-old mother of two was left lying and bleeding on the pavement after the incident.
'Handmade weapon'
Mr Abdallah, 56, was in a cafe next door to the library shortly after 13:00 BST when he heard screaming and went outside.
"There was a guy who was being very brave and another guy with a white baseball cap who he was trying to control and the man in the baseball cap suddenly pulled a gun from his bag".
After a brief scuffle, he said the man stepped back and the MP became involved.
Mr Abdallah said the weapon had "looked handmade" and a man who had been wrestling with the gunman continued even after seeing the gun.
He said: "The man stepped back with the gun and fired it and then he fired a second shot, as he was firing he was looking down at the ground."
"He was kicking her as she was lying on the floor", he said.
'Completely devastated'
Prime Minister David Cameron also tweeted to express his concern. "Our thoughts and prayers are with Jo and her family," he wrote.
Leeds North East MP Fabian Hamilton said he had known Mrs Cox since before she became an MP
Mr Hamilton said: "And I'm just completely devastated, I know Birstall reasonably well, and I think we're all totally shocked."
It has been announced the Vote Leave and Remain have suspended campaigning in the EU referendum in light of the attack.
Mrs Cox, who was born in Batley, was elected in 2015.
She was educated at Heckmondwike Grammar School and graduated from Cambridge University in 1995.
A former head of policy for Oxfam, she also worked as an adviser to Sarah Brown and Baroness Kinnock.
Mark Goldring, Oxfam's chief executive, said: " Oxfam is deeply shocked to hear the news. Our thoughts and sympathies are with Jo and her family at this difficult time." (BBC)