Can natural selection occur by chance or accident? No, with qualifications. Can evolution occur by chance or accident? Yes, definitely.
While tidying up my office I came across an anthology of articles by Richard Dawkins. It included a 2009 review of Jerry Coyne's book Why Evolution Is True (2009) and one of Richard's comments caught my eye because it illustrates the difference between the Dawkins' view of evolution and the current mainstream view that was described by Jerry in his book.
I can illustrate this difference by first quoting from Jerry Coyne's book.
This brings up the most widespread misunderstanding about Darwinism: the idea that, in evolution, "everything happens by chance" (also stated as "everything happens by accident"). This common claim is flatly wrong. No evolutionist—and certainly not Darwin—ever argued that natural selection is based on chance ....
True, the raw materials for evolution—the variations between individuals—are indeed produced by chance mutations. These mutations occur willy-nilly, regardless of whether they are good or bad for the individual. But it is the filitering of that variation by natural selection that produces natural selection, and natural selection is manifestly not random. (p. 119)
It's extremely important to notice that Coyne is referring to NATURAL SELECTION (or Dawinism) in this passage. Natural selection is not random or accidental, according to Coyne. This passage is followed just a few pages later by a section titled "Evolution Without Selection."
Let's take a brief digression here, because it's important to appreciate that natural selection isn't the only process of evolutionary change. Most biologists define evolution as a change in the proportion of alleles (different forms of a gene) in the population.
[Coyne then describes an example of random genetic drift and continues ...] Both drift and selection produce the genetic change that we recognize as evolution. But there's an important difference. Drift is a random process, while selection is the antithesis of randomness. Genetic drift can change the frequencies of alleles regardless of how useful they are to their carrier. Selection, on the other hand, always gets rid of harmful alleles and raises the frequencies of beneficial ones. (pp. 122-123)
Now let's look at Richard Dawkins' review of Coyne's book as published in the Times Literary Supplement in 2009 and reprinted in Books Do Furnish a Life (2021). I picked out an interesting passage from that review in order to illustrate a point.
Coyne is right to identify the most widespread misunderstanding about Darwinism as 'the idea that, in evolution, 'everything happens by chance' ... This common claim is flatly wrong.' Not only is it flatly wrong, it is obviously wrong, transparently wrong, even to the meanest intelligence (a phrase that has me actively restraining myself). If evolution worked by chance, it obviously couldn't work at all. (p. 427)
That last sentence is jarring to many scientists, including me. I think that the Dawkins' statement is 'obviously wrong' and 'transparently wrong' because, as Coyne pointed out, evolution by random genetic drift can occur by chance. [Let's not quibble about the meanings of 'random' and 'chance." That's a red herring in this context.] Clearly, evolution can work by chance so why does Dawkins say it can't?
It's not because Dawkins is unaware of random genetic drift and Neutral Theory. The explanation (I think) is that Dawkins restricts his definition of evolution to evolution by natural selection. From his perspective, the fixation of alleles by random genetic drift doesn't count as real evolution because it doesn't produce adaptations. That's the view that he described in The Extended Phenotype back in 1982 and the view that he has implicitly supported over the past few decades [Richard Dawkins' View of Random Genetic Drift].
This is one of the reasons why we refer to Dawkins as an adaptationist and it's one of the reasons why so many of today's evolutionary biologists—especially those who study evolution at the molecular level—reject the Dawkins' view of evolution in favor of a more pluralistic approach.
Note: I wrote an earlier version of this post in 2009 [Dawkins on Chance] and I wrote a long essay on Evolution by Accident where I describe many other examples of evolution by chance.