I initially thought it was a battery issue. I've seen things like this happen before when terminals were loose or earth points were corroded. Even a battery of the wrong type and ampage can cause things like this. The vehicle recently had a new battery fitted so the first thing I had to do was rule it out.
It turned out to be an fault in the brake light switch. The ECU, TCM etc were receiving intermittent data and were getting confused as to what the vehicle was actually doing. 110 dhs for a new switch and everything was as good as new.
So many people tell me they hate modern cars because there are so many electrical systems all communicating through computers and it's too complicated. My answer is always, it's not complicated, you just don't understand it. With a little bit of time and logical thinking, it's easy to fault find in modern cars when you have some understanding of how the systems operate and how they can affect each other. Personally, I much prefer working on stuff with modern injection and electronic ignition systems. It's so much easier than stripping down carburetors and distributors etc to see what's going on.