FRANKFURT — Ford Motor Company and Volkswagen are expected to sign an agreement as soon as next week to share the cost of developing autonomous vehicles and producing electric cars, according to two people with knowledge of the discussions.

The agreement, likely to be approved by Volkswagen’s supervisory board on Thursday, would deepen an existing alliance between the companies to produce pickup trucks, but would be much more ambitious. It would be the latest example of how longtime rivals are joining forces during a period of extraordinary ferment in the auto industry.

Battery-powered, self-driving cars have the potential to eliminate tailpipe emissions and avoid accidents caused by human error. But a rapid shift toward these technologies could be perilous for established carmakers like Ford and Volkswagen.

They must invest hundreds of billions of dollars in coming years or risk becoming irrelevant. And they face new competitors like Google and Uber with access to enormous financial resources. Investors have been much more willing to back Silicon Valley companies than the dinosaurs of Detroit or Wolfsburg, where Volkswagen is based.