Consider the Travelling Salesman Problem (TSP).
Decision Version (DV): Given an undirected weighted graph $G$, does there exist a Hamiltonian cycle of weight at most 'w' in the Graph?
Optimization Version (OV): Given an undirected weighted graph $G$, find the hamiltonian cycle of minimum weight?
Case 1: If P $=$ NP.
Since there is a polynomial-time reduction from DV to OV and vice-versa (link), both the problems are in P. Here, the complexity of both the problems are the same.
Case 2: If P $\neq$ NP
Here, we will show that the complexity of both the problems are different.
Note that the Decision version of TSP is in NP since given a sequence of vertices, we can verify in polynomial time if the sequence is a hamiltonian cycle of weight at most 'w'.
However, for the Optimization version of TSP, how will you know if it belongs to NP. In other words, given a Hamiltonian cycle of 'w', how can you verify if it is the optimal one? As per my thinking, to verify its optimality you must know the optimal solution. Since P $\neq$ NP, we can not find the optimal solution in polynomial time. Therefore, we might not be able to say if TSP is in NP.
Thus, the complexity of Decision Version and Optimization Version could be different.