Andrew Marr has become the angriest he has ever been with politicians.
Miliband had appeared on the show to promote a new Labour policy around rent controls while Johnson appeared to dismiss reports in Sunday's papers that his party would prefer he were leader instead of David Cameron.
Both discussed the prospect of the SNP backing a minority Labour government when they clashed at the end of the show.
Theresa May has described this as "the greatest constitutional crisis" in nearly 80 years, and Johnson talked up the prospect of Miliband "stabbing the country in the back" by doing a deal with Scottish nationalists.
This is what defence secretary Michael Fallon said, when he claimed Miliband did the same to his brother when he ran against him for the Labour leadership.
When they appeared together, the London mayor and Miliband argued over whether non-dom tax status should, as Labour has proposed, be abolished.
As they talked over each other, Johnson pointed at the Labour leader and said: "Hang on, is this the Ed Miliband who was in the treasury with Gordon Brown?" Miliband told him: "Don't get rattled."
Discussing the "backstabbing" remark, Miliband said Johnson was "put up to it" by Lynton Crosby, the Tories' campaign advisor, whom Miliband advised he sack if he becomes Tory leader."
As Johnson tried to come back, Marr held out his hand to say "we've run out time" but Johnson continued, shouting: "I'm not saying your brother had to present himself... with a dagger in the back and he would do more damage to this country than he did to his brother, and that is the key point."
"Best television of the week so far," the presenter said. "Enough, from both of you. Thanks to all my guests, including you two. Shut up now please."
He added: "Sorry."
Marr, who is regarded as a less aggressive interviewer than former BBC stablemate Jeremy Paxman, was praised telling them to shut up, with one tweeter calling it the best part of the programme.
Andrew Marr telling Boris to shut up was the best part of the whole programme #marr— Patsy (@PatsyS76) April 26, 2015
Earlier in the show, Johnson said claims he should immediately take over the Tories if they lost the election were "nonsense and trivial by comparison with the choice the country has to make in 11 days time".
"I think the risk to our country is that Labour, in concert with the SNP, would take it in profoundly the wrong direction," he said.
When asked whether he would do a deal with the SNP, Miliband said: "No coalition, no tie-ins. I have said no deals; honestly, I have been clear about that. I am not doing deals with the Scottish Nationalist Party. I am not interested in deals, no.”
“The way the House of Commons works is we want to put our Queen’s Speech before the House of Commons and other parties will vote.
"But I want to go to the substance of my disagreements with the SNP. I disagree with them on independence; clearly they want to break up the country and that would be absolutely a disaster for our country and is something I am not going to let happen.
"But there are other disagreements on the national defence, on the deficit and also on a bigger philosophy question, you know, I think, and in a way the Tories and SNP now have something in common, which is that they want to set one part of the country against another."