Was the telephone invented by accident?

Yes!

Mr. Bell invented the telephone by accident when he was trying to invent a device that could send more than one telegram at the same time