Hasan played five games for Lancashire in the early stages of the 2022 County Championship and thrived, taking 25 wickets at 20.60 including two five-wicket hauls, but the club did not pursue a renewal.
He has been a regular in Pakistan's squads across formats over the last six years but was dropped ahead of the T20 World Cup and has also lost his place in the Test squad ahead of England's tour next month.
If recalled to the limited-overs set-up, his availability could be limited by Pakistan's home white-ball series against New Zealand which runs from April 13-May 7, as well as potential involvement in the World Test Championship final.
"I'm delighted to sign for Warwickshire as they are an ambitious club and Edgbaston is a ground I've always enjoyed playing at," Hasan said. "I hope I can help the team with my experience and contribute to some wins - maybe even a trophy."
"He'll play a major role for us in both the Championship and the T20 Blast with his stay running from the start of the season and ending at the end of July. He's an established international bowler and a fantastic addition to our attack giving us something different to what we already have."
Warwickshire were Blast quarter-finalists last year but narrowly escaped relegation on the final day of the Championship season and have lost Dom Sibley (Surrey), Olly Stone (Nottinghamshire), Adam Hose (Worcestershire) and Matthew Lamb (Derbyshire) from last year's squad.
Hasan is the latest addition to their seam attack, with Ed Barnard (Worcestershire) and Chris Rushworth (Durham) arriving earlier in the winter, while Moeen Ali will return to the club in 2023 and play a prominent role in the Blast.