Was the iPhone 5 invented by accident?

No.
It was deliberately developed by a large team of engineers in various fields of electronics and computer science.