I believe birds evolved from dinosaurs. If you look at an ostrich (or even a chicken if it’s been plucked), you can see that they are not that different in form from dinosaurs like velociraptor. The feathers make them look rather different. I haven’t looked this up, but it’s my memory that feathers evolved before flight (although there were flying reptiles at the time of the dinosaurs, they’re not thought to be the direct ancestors of birds – I think).
Flightless birds would have evolved from dinos because their ancestors had some advantage over other creatures around at the time, so that they could live and breed more successfully, passing on their genes and gradually becoming better and better fitted to the environment. Whatever it was (and I suppose it might have just been good luck) they or their ancestors survived the catastrophe that wiped out most of the dinosaurs 65 million years ago.
This is a bit outside my area of expertise but I believe it was one of my scientific heroes, Thomas H. Huxley*, who first showed that birds had probably evolved from dinosaurs. As a result he was also the first to show (I believe) that some dinosaurs stood up on 2 legs. Before that, people had assumed they were all 4-legged.
As to how birds evolved and when the first true bird-like species appeared, I’m not sure. The earliest fossil (I think!) is of archaeopteryx – which is often depicted as a sort of cross between bird and dinosaur.
*Huxley was a good friend to Darwin and used to teach at the Royal School of Mines (now part of Imperial College where I work – my office is in the Huxley building: named in his honour!)