When they felt the two armies had been brawling long enough they gave the command to retreat and with their armies they marched back home

What is the correctly punctuated version of this sentence?
When they felt the two armies had been brawling long enough, they gave the command to retreat, and with their armies they marched back home.