The actor who shot to fame as a vampire in the Twilight films will take on another nocturnal hero: Batman. Pattinson, 33, inherits the role from Ben Affleck, whose tenure came to an end after the critical and commercial disappointments of Batman v Superman: Dawn of Justice and Justice League.

Pattinson’s first film as the billionaire crime fighter Bruce Wayne, who assumes a full-body black costume to battle baddies in Gotham City, will be titled The Batman, directed by Matt Reeves, and set for release in June 2021. Originally scheduled to start shooting in 2017, The Batman will be the first solo Caped Crusader film to form part of the DC Extended Universe.

The Warner Bros studio confirmed to Variety on Friday that Pattinson had beaten the other names on the shortlist – which included Nicholas Hoult – to the role. Following breakthrough performances in the Harry Potter and Twilight franchises, Pattinson has spent some years steering clear of the mainstream, instead working with directors such as David Cronenberg, David Michôd, the Safdie brothers and James Gray.

His recent collaboration with the French director Claire Denis, erotic sci-fi mystery High Life, won Pattinson considerable acclaim. He also stars in one of the best-reviewed films from this year’s Cannes festival: Robert Eggers’s The Lighthouse, an intense psychodrama set in 19th-century Maine.