It was an accident waiting to happen. A leaked email from one of Ed Miliband’s closest aides described as a “nightmare” the process of reaching agreement with the shadow Chancellor Ed Balls on the line to take on the economic recovery. It was mistakenly copied to a Conservative MP with the same name as Labour’s pollster, James Morris, and emerged in the Mail on Sunday.

To some Labour MPs, the only surprise was that the tensions between Mr Miliband and Mr Balls have not surfaced more often. They can be traced back to the Labour leadership election the two men contested in 2010. Mr Miliband argued that the market-based economic system put in place in the Thatcher era was broken. Mr Balls believed the answer was not to turn the system upside down, but a fiscal stimulus instead of Coalition cuts that went “too far, too fast”. Mr Miliband did not make Mr Balls his shadow Chancellor when he won the top job, only to change his mind three months later when his first choice, Alan Johnson, quit for personal reasons.

What followed was a marathon bout of arm-wrestling between the two Eds. In public, they insisted they had learned the lessons from their ringside seats at the bruising battles between Tony Blair and Gordon Brown. They both worked as aides to the former Chancellor before becoming MPs and ministers.

Download the new Independent Premium app Sharing the full story, not just the headlines

In private, Mr Balls argued that Labour should focus on his five-point plan to kickstart the economy, including a temporary cut in VAT. Mr Miliband saw that as backward-looking to 2010, insisting that Labour needed to look forward to 2015. It was a painful process, but the Labour leader gradually weaned his shadow Chancellor off his cherished plan. Their relationship improved when they reached a new settlement this summer. With economic growth set to return, Labour would switch the spotlight from the “failure” of George Osborne’s Plan A to the “cost of living crisis”.

Mr Balls, anxious to regain Labour’s economic credibility, insisted the party stick to the Coalition’s day-to-day spending total for the first year of the next parliament if it wins power in 2015. Mr Miliband, anxious to show how Labour would be different to the other parties, kept alive his plan to borrow more to outspend the Coalition on building projects such as housing.

Although the atmosphere improved markedly after this deal, allies of both men admit privately some differences of approach remain. Mr Balls has been uncomfortable with what is seen as Mr Miliband’s “anti-business” rhetoric. “Ed M is playing politics. Ed B is thinking about government,” said one senior Labour MP. “Ed B does not want to undermine the leader. But he is trying to inject a dose of reality into the leader’s ambitious vision for the country.”

After a miserable summer for Mr Miliband in which Labour disappeared off the public radar, Mr Balls created shockwaves at the party’s September conference by calling into question Labour’s backing for the HS2 north-south rail project. Team Miliband saw this as a challenge to his authority because he supports the scheme. He fought back with his pledge to freeze energy prices, about which Mr Balls was initially cautious. Mr Miliband scored a political bullseye, while Mr Balls appeared to retreat on HS2. “We put him back in his box,” one backbench ally of Mr Miliband crowed.

MPs close to Balls insist his speech on the rail link had been cleared by Mr Miliband at least 10 days before he made it. Similarly, they say the two Eds met and agreed the very line on the economy that provoked the “nightmare” remark in the fateful email by Torsten Bell, Labour’s director of policy – that the party should focus on “cost of living/recovery built to last/economy works for working people.” The same words featured in the statement Labour issued later so Mr Miliband did not veto them. “Some people in the [Miliband] office don’t like being out of the room,” said an MP close to Balls. “The two Eds have learned that it’s best to resolve any issues on a one-to-one basis, rather than leaving it to advisers as Tony and Gordon often did. That allows the advisers to fuel any problems. It is much better to nip them in the bud.”

Although the Miliband and Balls camps insist that there has been a significant rapprochement between the two men since their July deal, they may need rather a lot of one-to-one meetings before the 2015 election. Mr Balls is more open to backing a referendum on Europe than Mr Miliband. The shadow Chancellor favours expansion at Heathrow Airport, which the Labour leader opposes. Above all, they must reach agreement on the tax and spending plans to be included in the party’s manifesto.

Mr Miliband has a ruthless streak and there is persistent speculation he might move Mr Balls from the Treasury brief to show a symbolic break with the party’s past mistakes on the economy. It is very unlikely to happen. Despite their differences, Mr Miliband regards Mr Balls as the best qualified man to be his Chancellor. And there is one thing the two men definitely agree on: they sink or swim together.