Barney explained that he broke his foot changing a light bulb in the bathroom when his foot slipped and fell into the toilet (he thought the lid was down). Hal Linden broke his foot in 1976 while filming a TV music special, and the injury was written into the show. The break happened towards the end of Season 2, so only two episodes ( The Kid (1976) & The Mole (1976) ) had Barney's leg in a cast.
Charles Murphy, who played the accountant Eugene Woolen from Fear of Flying (1976), shows up to continue his story line from that episode.